Paul Lassiter
Paul Lassiter

Reputation: 2771

How to reduce all whitespace in a string to single spaces?

Using VB6 without any additional references such as Regex, how can I convert a string so that all whitespace in a string is reduced to single spaces?

eg.

" A    B C D   E"

would be converted to

"A B C D E"

Upvotes: 1

Views: 3210

Answers (1)

Paul Lassiter
Paul Lassiter

Reputation: 2771

Function NormalizeSpaces(s As String) As String

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

End Function

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

Upvotes: 5

Related Questions