VBA Removing Special Characters

I need a function that completely removes all special characters (visible / invisible) from a string, except for AZ, az, 0-9. I already prepared some function in advance, and I found its left commas (,) somehow: O. and maybe I don't know anymore. Could you take a look and consult:

Function RemoveSpecialChars(Tekst As String) As String

        Dim a$, b$, c$, i As Integer

        a$ = Tekst
        For i = 1 To Len(a$)
            b$ = Mid(a$, i, 1)
            If b$ Like "[A-Z,a-z,0-9]" Then
                c$ = c$ & b$
            End If
        Next i

        RemoveSpecialChars = c$

End Function
+4
source share
1 answer

Just remove the commas:

If b$ Like "[A-Za-z0-9]" Then

As the MSDN for Visual Basic says :

To specify multiple ranges for the same character position, place them in the same brackets without separators. For example, [A-CX-Z] results in a match if the corresponding character position in the string contains any character within the AC range or XZ range.

MSDN VBA, .

+4

Source: https://habr.com/ru/post/1542006/


All Articles