Reputation: 8772
Is there a way to parse utf codes in vbscript? What I'd like to do is replace all codes like "\u00f1" in a string for its corresponding character.
Upvotes: 2
Views: 2399
Reputation: 98082
The Unescape
function does that*, only it requires that the Unicode characters are encoded in the %u***xxxx*
format. So, you'll need to replace the \u***xxxx*
codes with their **%u***xxxx*
equivalents first. Here's an example:
str = "\u0044\u006F \u0063\u0061\u0074\u0073 \u0065\u0061\u0074 \u0062\u0061\u0074\u0073\u003f"
Set re = New RegExp
re.Pattern = "\\(u[a-f\d]{4})"
re.IgnoreCase = True
re.Global = True
str2 = Unescape(re.Replace(str, "%$1"))
MsgBox str2
* Note that Unescape
also replaces the %***xx*
codes in the string with the corresponding ASCII characters. So, if %***xx*
is a legal substring in your string, you'll have to write your own replacement function. Such a function could do the following:
**\u***xxxx*
-like substrings in your input string,ChrW
to convert the decimal character code to the corresponding Unicode character,**\u***xxxx*
match with the coresponding character.Upvotes: 1