Hàm sau sẽ cắt bớt các khoảng trống dư thừa trong 1 chuỗi
Private Function PreventDuplicateSpaces(Word)
Dim i, WordLength, Character, LastCharacter, NewWord
On Error GoTo ErrorHandler
WordLength = Len(Word)
For i = 1 To WordLength
Character = Mid(Word, i, 1)
If LastCharacter = " " And Character = " " Then
Else
NewWord = NewWord & Character
LastCharacter = Character
End If
Next i
PreventDuplicateSpaces = Trim(NewWord)
Exit Function
ErrorHandler:
End Function
(Theo http://vb-helper.com)
Private Function PreventDuplicateSpaces(Word)
Dim i, WordLength, Character, LastCharacter, NewWord
On Error GoTo ErrorHandler
WordLength = Len(Word)
For i = 1 To WordLength
Character = Mid(Word, i, 1)
If LastCharacter = " " And Character = " " Then
Else
NewWord = NewWord & Character
LastCharacter = Character
End If
Next i
PreventDuplicateSpaces = Trim(NewWord)
Exit Function
ErrorHandler:
End Function
(Theo http://vb-helper.com)