有什么方法可以删除字符串中的空格吗?
var str = "The store is 5 6 7 8"
处理后的输出应该是这样的:
"The store is 5678"
如何做到这一点?
最佳答案
这与 santosh singh 的回答非常接近,但不会替换 is
和 5
之间的空格。
const regex = /(\d)\s+(?=\d)/g;
const str = `The store is 5 6 7 8`;
const subst = `$1`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
关于javascript - js代码删除字符串中数字之间的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47506828/