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)

2 Likes

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.

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.