且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从字符串中剥离汉字(vba)

更新时间:2023-11-14 08:42:22

您可以使用Regexp去除中文unicode字符

You can use a Regexp to strip the Chinese unicode characters

***在下面列出了相关字符

Wikipedia lists the relevant characters below

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

因此,此正则表达式将删除这些范围.我已经使用了 aldo.roman.nurena的字符串示例

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