删除字符串中的Unicode字符 [英] Remove Unicode characters in a String

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

问题描述

如何删除VBA中不属于ASCII类别的所有特殊字符?

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.

Œ–Ššƒƒ

Œ œ Š š Ÿ ƒ

还有更多这样的字符.

There are many more such characters.

这些不属于ASCII类别,因为您可以在此处 http://www.ascii. cl/htmlcodes.htm

These don't belong to ASCII category as you can see here http://www.ascii.cl/htmlcodes.htm

我尝试过类似的事情

strName = Replace(strName, ChrW(376), " ")

推荐答案

您会感兴趣的RegEx解决方案吗?

Would a RegEx solution be of interest to you?

此站点上有很多针对不同语言的示例-这是C#:

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#).

尝试使用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

这篇关于删除字符串中的Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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