[英]What is the JavaScript equivalent for the vbscript Chr() function?
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)
什么是等效的
Chr(10)
cOrderNumList = frmSearch.OrderNumList.Value;
cOrderNumList = cOrderNumList.replace(String.fromCharCode(10), "");
aOrderNumList = cOrderNumList.split(",");
Are my changes correct? 我的更改是否正确?
cOrderNumList = Replace(cOrderNumList, String.fromCharCode(10), "")
To convert a char code to a string you can do this: 要将char代码转换为字符串,您可以执行以下操作:
var outputString = yourString.replace(cOrderNumList, String.fromCharCode(10))
As you will notice, this converts the char code to a one-letter string. 正如您将注意到的,这会将char代码转换为单字母字符串。 You can't truly convert to a pure char because the char type doesn't exist in JavaScript.
您无法真正转换为纯char,因为JavaScript中不存在char类型。
You can use String.fromCharCode but 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, "")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.