Remove Unicode characters in a String

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

    Supposing you have:

    Then the following code will get the String from A1 and let through only ANSI (code 0 to 255) in A2.

    Sub test()
     Dim s1 As String, s2 As String, c As String, i As Long, iAsc As Integer
    
     s1 = Range("A1").Value
    
     s2 = ""
    
     For i = 1 To Len(s1)
      c = Mid(s1, i, 1)
      iAsc = AscW(c)
      If iAsc <= 255 Then
       s2 = s2 & c
      End If
     Next
    
     Range("A2").Value = s2
    
    End Sub
    

提交回复
热议问题