string mystring = "bbbccc ";
How to check if my string contains more than one consecutive whitespace?
string mystring = "bbbccc ";
How to check if my string contains more than one consecutive whitespace?
I assume you're looking for multiple consecutive whitespaces.
I'd use System.Text.RegularExpressions.Regex
for that.
Regex regex = new Regex(@"\s{2,}"); // matches at least 2 whitespaces
if (regex.IsMatch(inputString))
// do something
This is probably a fast implementation:
public static bool HasConsecutiveSpaces(string text)
{
bool inSpace = false;
foreach (char ch in text)
{
if (ch == ' ')
{
if (inSpace)
{
return true;
}
inSpace = true;
}
else
{
inSpace = false;
}
}
return false;
}
But if you don't really need to worry about speed, just use the regexp solution given in a previous answer.