robertb_NZ
Well-known member
I have written this routine which seems to work perfectly, but is there a better way (more efficient, more concise) ?
Function ReplaceCommas(Linein As String) As String
' Replace "," with " ", except where they are within a string
Dim SB As New StringBuilder
Dim StringState As Boolean = False
For I = 1 To Len(Linein)
Dim Char1 As String = Mid(Linein, I, 1)
If Char1 = "'" Then StringState = Not StringState
If Char1 = "," AndAlso Not StringState Then
SB.Append(" ")
Else
SB.Append(Char1)
End If
Next
Return SB.ToString
End Function
Function ReplaceCommas(Linein As String) As String
' Replace "," with " ", except where they are within a string
Dim SB As New StringBuilder
Dim StringState As Boolean = False
For I = 1 To Len(Linein)
Dim Char1 As String = Mid(Linein, I, 1)
If Char1 = "'" Then StringState = Not StringState
If Char1 = "," AndAlso Not StringState Then
SB.Append(" ")
Else
SB.Append(Char1)
End If
Next
Return SB.ToString
End Function