How to remove extrace spaces between string?

I have two variables which is var a and b and I wanted to compare them but in the extraction there was empty spaces. Both strings are equal the only difference is spaces , how do we remove the spaces to make them equal ? Thank you.

var = "Char Wicked"
var b = "Char     Wicked"

Any idea would be appreacited. Thanks guys.

answer "\s","") . using regex.replace

For Comparison you can use this

a.Replace(" “, “”).ToLower.Equals(b.Replace(” “,”").ToLower)

1 Like

Hi

Please try this :

string a = System.Text.RegularExpressions.Regex.Replace(“check String”, @"\s", “”)
string b = System.Text.RegularExpressions.Regex.Replace(“check string”, @"\s", “”)
if String.Compare(a, b, true) == 0

1 Like

Personally I would use this regex.
http://regexstorm.net/tester?p=\s{2%2C}&i=Char+++Wicked&r=+

It will replace empty spaces (more than 2) with an empty space.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.