Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Char to UTF code in vbscript

Tags:

utf

vbscript

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?

like image 406
Carlos Blanco Avatar asked Feb 10 '10 23:02

Carlos Blanco


People also ask

What is CHR 34 in VBScript?

In two of the arguments, you have opening quotation marks embedded in the string (that's what the Chr(34) represents), but no closing quote. While that's legal VBScript code, it probably won't work the way you intended.

What is the use of the CHR () function in VBScript?

The Chr function converts the specified ANSI character code to a character. Note: The numbers from 0 to 31 represents nonprintable ASCII codes, i.e. Chr(10) will return a linefeed character.


1 Answers

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
like image 129
Helen Avatar answered Oct 12 '22 17:10

Helen