简体   繁体   English

什么是vbscript Chr()函数的JavaScript等价物?

[英]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? 我的更改是否正确?

你需要String.fromCharCode()

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.

相关问题 什么是VBScript CreateObject()的等效JavaScript函数 - what is the equivalent JavaScript function for VBScript CreateObject() 什么是 javascript 中等效的 php chr() 和 ord() 函数 - What is equivalent php chr() and ord() functions in javascript vbscript Mid ZC1C425268E68385D1AB5074C17A 的 javascript 等效 function 是什么? 是 substring() 还是 substr()? - what is the javascript equivalent function for vbscript Mid function? is that substring() or substr()? vbscript TypeName的javascript等效项是什么? - what is the javascript equivalent for vbscript TypeName? vbscript MsgBox()的Javascript等效函数 - Javascript equivalent function for vbscript MsgBox() 如何编写 JavaScript function 相当于 PHP 的 chr() function? - How to write JavaScript function equivalent of PHP's chr() function? VBScript的RegExp函数到底能做什么,以及与javascript等价的东西是什么? - What exactly does VBScript's RegExp function do and what is the javascript equivalent? 相当于vbscript setlocale的Javascript - Javascript equivalent of vbscript setlocale 什么是vbscript的“javascript”等价物“window.onBeforeUnload = Nothing” - what is the javascript equivalent for vbscript “window.onBeforeUnload = Nothing” Javascript/NodeJs 中这个 function 的等价物是什么? - What is the equivalent of this function in Javascript/NodeJs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM