从字符串中剥离汉字(vba) [英] Strip Chinese Characters from a string (vba)

查看:830
本文介绍了从字符串中剥离汉字(vba)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Project VBA将我的活动名称从英语翻译为中文.

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

我的问题是我在一些英文活动名称中嵌入了一些中文翻译.我想先去除汉字,然后再将字符串传递给Microsoft Translator.

My problem is I have some Chinese translations embedded in some of the English activity names. I want to strip out the Chinese characters before passing the string to Microsoft Translator.

关于我该怎么做的任何想法?

Any ideas as to how I can do that?

推荐答案

您可以使用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

这篇关于从字符串中剥离汉字(vba)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆