Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check does string contain more than one white space [duplicate]

Tags:

string

c#

string mystring = "bbbccc  ";

How to check if my string contains more than one consecutive whitespace?

like image 314
user1765862 Avatar asked Nov 24 '25 06:11

user1765862


1 Answers

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
like image 86
Nolonar Avatar answered Nov 25 '25 19:11

Nolonar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!