I needed to remove all characters except letters and numbers from a string in the joyful language that is MapBasic. Might not be the most efficient way of doing it but it works doesn’t it?
Function RemoveSpecialChars(byval str as string) as String
Dim chr, out, nicechars as String
Dim i, l as Integer
nicechars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
l = Len(str)
For i = 1 to l
chr = Mid$(str, i, 1)
If InStr(1, nicechars, chr) > 0 Then
out = out + chr
End If
Next
RemoveSpecialChars = out
End Function
Advertisement