Remove Unicode characters in a String

前端 未结 6 863
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 06:56

How do I remove all special characters which don\'t fall under ASCII category in VBA?

These are some of the symbols which appear in my string.

<
6条回答
  •  长情又很酷
    2020-12-11 07:16

    Don't need to loop each character

    Maybe late, but maybe it helps someone:

    Public Function StripNonAsciiChars(ByVal InputString As String) As String
        Dim i As Integer
        Dim RegEx As Object
        Set RegEx = CreateObject("VBScript.RegExp")
        With RegEx
            .Global = True
            .MultiLine = True
            .IgnoreCase = True
            .Pattern = "[^\u0000-\u007F]"
            StripNonAsciiChars = Application.WorksheetFunction.Trim(RegEx.Replace(InputString, " "))
        End With
    End Function
    

提交回复
热议问题