如何将字符串中的所有空格减少到单个空格?

Pau*_*ter 1 string vb6 whitespace trim removing-whitespace

使用VB6 而不使用任何其他引用(如Regex),如何转换字符串以使字符串中的所有空格都缩减为单个空格?

例如.

" A    B C D   E"
Run Code Online (Sandbox Code Playgroud)

将被转换为

"A B C D E"
Run Code Online (Sandbox Code Playgroud)

Pau*_*ter 5

Function NormalizeSpaces(s As String) As String

    Do While InStr(s, String(2, " ")) > 0
        s = replace(s, String(2, " "), " ")
    Loop
    NormalizeSpaces = s

End Function
Run Code Online (Sandbox Code Playgroud)

(来自:http://www.techrepublic.com/article/normalizing-spaces-in-vb6-strings/5890164)