简体   繁体   English

如何在Javascript中使用一组字符拆分子字符串上的字符串?

[英]How to split a string on substrings with set of characters in Javascript?

Is there a quite simple way to split a string on substrings with set of characters like without using Regexp ?是否有一种非常简单的方法可以在不使用 Regexp 的情况下使用字符集拆分子字符串上的字符串?

abcd..,,qqww..::ss       - input
.,:    - characters
abcd qqww ss   - substrings

I would appreciate any suggestions.我将不胜感激任何建议。

You can use .replace() to pass in the values you don't want present in the output.您可以使用.replace()传入您不希望出现在输出中的值。

var str = 'abcd..,,qqww..::ss ';
var newStr = str.replace(/[.,:]/g,''); // if you want to replace them with spaces, change '' to ' '
alert(newStr) // results in abcdqqwwss

https://jsfiddle.net/kdqtpcq9/ https://jsfiddle.net/kdqtpcq9/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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