- Home
·
- String Manipulation
·
- This simple code removes leading, trailing and inner extra spaces from a string, e.g. the string
This simple code removes leading, trailing and inner extra spaces from a string, e.g. the string
This simple code removes leading, trailing and inner extra spaces from a string, e.g. the string " hello to you " will be converted to "hello
Rate This simple code removes leading, trailing and inner extra spaces from a string, e.g. the string
(2(2 Vote))
Dim myStr As String
myStr = str
' Remove leading spaces
While (Left(myStr, 1) = " ")
myStr = Mid(myStr, 2, Len(myStr) - 1)
Wend
' Remove trailing spaces
While (Right(myStr, 1) = " ")
myStr = Left(myStr, Len(myStr) - 1)
Wend
' Every two adjacent words are separated by one space only
Dim Position As Integer
Dim EndOfString As Boolean
Position = 1
EndOfString = False
While EndOfString = False
While Mid(myStr, Position, 1) <> " " And Position < Len(myStr)
Position = Position + 1
Wend
If Mid(myStr, Position, 1) = " " And Mid(myStr, Position + 1, 1) = " " Then
myStr = Left(myStr, Position - 1) & Mid(myStr, Position + 1, Len(myStr) - Position)
Position = 1
End If
If Position = Len(myStr) Then
EndOfString = True
Else
Position = Position + 1
End If
Wend
RemoveExtraSpaces = myStr
End Function
This simple code removes leading, trailing and inner extra spaces from a string, e.g. the string Comments
No comments yet — be the first to post one!
Post a Comment