blog vipa
mój dzień to 3 filiżanki kawy

blog vipa

How to simplify the whitespaces in .NET System.String

Kwiecień 20th, 2007 . by vip

If you’ve got ”  some      spaces  here    in    string    „, and want only single spaces, you can use System.Text.RegularExpressions space.
The only line would give you only one space instead of many.

[csharp]output = Regex.Replace(input, @”\s+”, ” „);[/csharp]

To remove spaces from the beggining and end, consider the String.Trim method.

Leave a Reply