VBScript chr() appears to return wrong value

*爱你&永不变心* 提交于 2019-12-10 18:39:33

问题


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?


回答1:


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



回答2:


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




回答3:


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

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



来源:https://stackoverflow.com/questions/315719/vbscript-chr-appears-to-return-wrong-value

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