vbscript Chr() 函数的 JavaScript 等效项是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13875131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the JavaScript equivalent for the vbscript Chr() function?
提问by Madura Harshana
I need to convert following lines to JavaScript:
我需要将以下行转换为 JavaScript:
cOrderNumList = frmSearch.OrderNumList.Value
cOrderNumList = Replace(cOrderNumList, Chr(10), "")
aOrderNumList = Split(cOrderNumList,",")
What is the JavaScript equivalent of Chr(10)
什么是 JavaScript 等价物 Chr(10)
回答by user160820
cOrderNumList = frmSearch.OrderNumList.Value;
cOrderNumList = cOrderNumList.replace(String.fromCharCode(10), "");
aOrderNumList = cOrderNumList.split(",");
Are my changes correct?
我的更改正确吗?
回答by Sirko
You need String.fromCharCode():
cOrderNumList = Replace(cOrderNumList, String.fromCharCode(10), "")
回答by Denys Séguret
You can use String.fromCharCodebut if your character is hardcoded, the best is to simply use "\n".
您可以使用String.fromCharCode但如果您的字符是硬编码的,最好是简单地使用"\n".
And as replace would only replace the first one, I suggest this simple regular expression :
由于替换只会替换第一个,我建议使用这个简单的正则表达式:
cOrderNumList = cOrderNumList.replace(/\n/g, "")
回答by Levi Botelho
To convert a char code to a string you can do this:
要将字符代码转换为字符串,您可以执行以下操作:
var outputString = yourString.replace(cOrderNumList, String.fromCharCode(10))
As you will notice, this converts the char code to a one-letter string. You can't truly convert to a pure char because the char type doesn't exist in JavaScript.
您会注意到,这会将字符代码转换为单字母字符串。您无法真正转换为纯 char,因为 JavaScript 中不存在 char 类型。

