简体   繁体   中英

convert c# to javascript here. - javascript change string to array

我如何将c#代码转换为javascript以完成相同的操作。

var s = styles.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

If styles is a string, it's as simple as:

styles.split(/[\r|\r\n]/);

 var styles = 'body {font-size: 12px;}\\n\\ .someClass {color: red}'; document.querySelector('#result').textContent = '[' + (styles.split(/[\\r|\\r\\n]/)) +']'; 
 <pre id="result"></pre> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM