Remove Unicode characters in a String

前端 未结 6 852
没有蜡笔的小新
没有蜡笔的小新 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:08

    Would a RegEx solution be of interest to you?

    There are plenty of examples for different languages on this site - here's a C# one: How can you strip non-ASCII characters from a string? (in C#).

    Try this for VBA:

    Private Function GetStrippedText(txt As String) As String
        Dim regEx As Object
    
        Set regEx = CreateObject("vbscript.regexp")
        regEx.Pattern = "[^\u0000-\u007F]"
        GetStrippedText = regEx.Replace(txt, "")
    
    End Function
    

提交回复
热议问题