Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Unicode characters in a String

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.

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

I tried something like this

strName = Replace(strName, ChrW(376), " ")
like image 776
Jeevan Avatar asked May 04 '16 09:05

Jeevan


People also ask

How do I remove Unicode characters in Word?

Once identified, Use Word's Find and Replace (CTRL H) and enter: ^u8203 and replace with nothing, or with whatever character desired.


1 Answers

Would a RegEx solution be of interest to you?

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

Try this for 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
like image 183
Ambie Avatar answered Oct 05 '22 10:10

Ambie