3 replies
by bob sellman
If you put the following code (substituting your text for the sample text and dropping the msgbox that shows the results), it will do exactly what you ask. In fact, I've written it in a way that allows you to easily strip any selected character from the text.
Dim strSource As String
strSource = "This is a test." 'sample text
Dim strResult As String 'result ends up here
Dim lngLength As Long 'length of original string
Dim strEliminate As String ' what to eliminate
strEliminate = " " 'eliminate a space
Dim intWhere As Integer ' track where we are
Dim intX As Integer ' counter
strResult = "" ' set starting string to null
lngLength = Len(strSource)
MsgBox lngLength
For intX = 1 To lngLength
intWhere = InStr(intX, strSource, strEliminate) ' see if space is in remainder of text
If intWhere = 0 Then
strResult = strResult & MID$(strSource, intX, lngLength - intX + 1)
intX = lngLength + 1
Else
strResult = strResult & MID$(strSource, intX, intWhere - intX)
intX = intWhere
End If
Next intX
' display initial string and stripped result
MsgBox "starting string: " & strSource & vbNewLine & "result: " & strResult
This should do what you want.
by ron a. g.
by ron a. g.
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending