4

I'm trying to convert a character code to a character with chr(), but VBScript isn't giving me the value I expect. According to VBScript, character code 199 is:

�

However, when using something like Javascript's String.fromCharCode, 199 is:

Ç

The second result is what I need to get out of VBScript's chr() function. Any idea what the problem is?

David Brown
  • 35,411
  • 11
  • 83
  • 132

3 Answers3

8

Edited to reflect comments

Chr(199) returns a 2-byte character, which is being interpreted as 2 separate characters.

  • use ChrW(199) to return a Unicode string.
  • use ChrB(199) to return it as a single-byte character
Alex
  • 1,457
  • 1
  • 13
  • 26
Jimmy
  • 89,068
  • 17
  • 119
  • 137
  • 2
    ChrB worked if I wasn't concatenating the character onto a string. ChrW appears to work with string concatenation (don't ask me why). Thanks! – David Brown Nov 24 '08 at 22:34
0

Encoding is the problem. Javascript may be interpreting as latin-1; VBScript may be using a different encoding and getting confused.

strager
  • 88,763
  • 26
  • 134
  • 176
0

The fromCharCode() takes the specified Unicode values and returns a string.

The Chr() function converts the specified ANSI character code to a character.

Kate Orlova
  • 3,225
  • 5
  • 11
  • 35
Daniel Kreiseder
  • 12,135
  • 9
  • 38
  • 59