Strip Chinese Characters from a string (vba)

后端 未结 2 1577
别那么骄傲
别那么骄傲 2021-01-03 17:01

I am using Microsoft Project VBA to translate my activity names from English to Chinese.

My problem is I have some Chinese translations embedded in some of the Engl

2条回答
  •  借酒劲吻你
    2021-01-03 17:39

    You can use a Regexp to strip the Chinese unicode characters

    Wikipedia lists the relevant characters below

    enter image description here

    Sub Test()
    Dim myString as String
    myString = "This is my string with a " & ChrW$(&H6C49) & " in it."
    Dim objRegex As Object
    Set objRegex = CreateObject("vbscript.regexp")
    With objRegex
        .Global = True
        .Pattern = "[\u4E00-\u9FFF\u6300-\u77FF\u7800-\u8CFF\u8D00-\u9FFF]+"
        MsgBox .Replace(myString, vbNullString)
    End With
    End Sub
    

    So this regexp will strip out these ranges. I have used aldo.roman.nurena's string example

提交回复
热议问题