我的字符串有一些问题,变量名称是 accountcode
。我只想要字符串的一部分。我想要第一个 ,
之后的字符串中的所有内容,排除逗号后的任何多余空格。例如:
accountcode = "xxxx, tes";
accountcode = "xxxx, hello";
然后我想输出像 tes
和hello
.
我尝试过:
var s = 'xxxx, hello';
s = s.substring(0, s.indexOf(','));
document.write(s);
最佳答案
只需将split
与trim
结合使用即可。
var accountcode = "xxxx, tes";
var result= accountcode.split(',')[1].trim();
console.log(result);
关于javascript - 获取字符串中单个逗号后的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53312293/