Char to UTF code in vbscript

2019-02-17 23:33发布

I'd like to create a .properties file to be used in a Java program from a VBScript. I'm going to use some strings in languages that use characters outside the ASCII map. So, I need to replace these characters for its UTF code. This would be \u0061 for a, \u0062 fro b and so on.

Is there a way to get the UTF code for a char in VBScript?

标签: vbscript utf
1条回答
做个烂人
2楼-- · 2019-02-17 23:54

VBScript has the AscW function that returns the Unicode (wide) code of the first character in the specified string.

Note that AscW returns the character code as a decimal number, so if you need it in a specific format, you'll have to write some additional code for that (and the problem is, VBScript doesn't have decent string formatting functions). For example, if you need the code formatted as \unnnn, you could use a function like this:

WScript.Echo ToUnicodeChar("✈") ''# \u2708

Function ToUnicodeChar(Char)
  str = Hex(AscW(Char))
  ToUnicodeChar = "\u" & String(4 - Len(str), "0") & str 
End Function
查看更多
登录 后发表回答