I have a lot of strings that look like this:
current affairs
and i want to make the string be :
current affairs
i try to use Trim()
but it won't do the job
Regex can do the job
string_text = Regex.Replace(string_text, @"\s+", " ");
You can use regular expressions for this, see Regex.Replace
:
var normalizedString = Regex.Replace(myString, " +", " ");
If you want all types of whitespace, use @"\s+"
instead of " +"
which just deals with spaces.
var normalizedString = Regex.Replace(myString, @"\s+", " ");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With