I want to check how many successing spaces are in my string. It should be no more than one.
For example:
this is ok
this is NOT ok
thisisok
this is NOT ok
I want to check how many successing spaces are in my string. It should be no more than one.
For example:
this is ok
this is NOT ok
thisisok
this is NOT ok
You can test to see if two consecutive spaces exist in the string, as that will also cover any string of spaces longer than 2. You can do this using the Contains
method:
string testString = "this is not OK";
if (testString.Contains(" "))
{
// Bad
}
This should get you the logic for succession spaces in string literal
static void Main(string[] args)
{
string str = "this is NOT ok";
int index = str.IndexOf(' ');
//check if next character of space is also a space
if (index >= 0 && str[index + 1] == ' ')
Console.WriteLine("Not Ok String");
else
Console.WriteLine("OK String");
}