-3

I'm looking for a efficient way for removing all of the white spaces in an string. I have checked replace (replace(' ','')) but I'm looking for a more efficient way. I'd appreciate the help.

6

1 Answer 1

0

You may use Regular Expression.

For example:

var result=System.Text.RegularExpressions.Regex.Replace(input, @"\s+", "");

Input is your string

See more Removing whitespaces using C#

Sign up to request clarification or add additional context in comments.

2 Comments

"must" is a strong word here. You can. Alternatively, you could also use something like new string(input.Where(c => !char.IsWhiteSpace(c)).ToArray()). Since Regex isn't magic, it probably does something very similar to that.
thanks you for comment, i already edit @Corak

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.