<分区>
我想检查我的字符串中有多少个连续的空格。不应超过一个。
例如:
this is ok
this is NOT ok
thisisok
this is NOT ok
<分区>
我想检查我的字符串中有多少个连续的空格。不应超过一个。
例如:
this is ok
this is NOT ok
thisisok
this is NOT ok
最佳答案
您可以测试字符串中是否存在两个连续的空格,因为这也会覆盖任何长度超过 2 的空格字符串。您可以使用 Contains
方法执行此操作:
string testString = "this is not OK";
if (testString.Contains(" "))
{
// Bad
}
关于c# - 如何检查字符的连续性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32334865/