Remove excess white space from string

maria picture maria · Apr 14, 2011 · Viewed 20.2k times · Source

I want to remove the excess white spaces using VB.net

ex.

"The   Quick          Brown Fox"

I want output

"The Quick Brown Fox"

Thanks, inchika

Answer

Fredrik Mörk picture Fredrik Mörk · Apr 14, 2011

You can use a simple regular expression for that:

Dim cleaned As String = Regex.Replace(input, "\s{2,}", " ")