Hello,
I'm new to VB coding. Please take a look at the code below and tell me if you spot any problems. The purpose of this function is to take a string as input and to remove extraneous spaces -- that is, replace multiple instances of space characters with a single space character.
The logic of the code seems fine, however, I think I'm missing something. It seems when I call this function from elsewhere in the project, the code doesn't finish executing. I'm not sure if it's a debugger problem or what, but the code seems to get to the IF statement inside the FOR loop, but then immediately exits.
I have no idea why that would happen.... Any ideas?
Private Function stripSpaceCharacters(s As String) As String
Dim i As Integer
Dim iStart As Integer
Dim sNew As String
sNew = s
For i = 0 To Len(sNew) - 1
If Mid(sNew, i, 1) = " " Then
iStart = i
Do While Mid(sNew, i, 1) = " "
i = i + 1
Loop
sNew = left(sNew, iStart+1) & Mid(sNew, i)
End If
Next
stripSpaceCharacters = sNew
End Function