Char to UTF code in vbscript

寵の児 提交于 2019-11-28 04:58:51

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/2241130/char-to-utf-code-in-vbscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!