This article mainly introduces JS using the Split function according to multiple characters to split the string method, the example analysis of the use of Split function skills, very practical value, the need for friends can refer to the next
The example in this paper describes how JS uses the Split function to divide a string by multiple characters. Share to everyone for your reference. The specific analysis is as follows:
JS in the split () function can be divided into a string according to the specified symbol, but if there is more than one split in the string, JS's split () function can also be competent, the answer is yes, JS's split () function can be implemented by regular expression of multi-delimiter string segmentation, The invocation is also very simple, here is a detailed example.
The following code can divide a string by a comma by using the JS split method
?
12 |
var mystring = "a,b,c,d,e" ; var myarray = mystring.split( "," ); |
If there is such a string: "Jb51.net,google.com,baidu.com_weibo.com_haotu.net",
We want to split the site address by commas and underscores at the same time, referring to the following code:
?
12 |
var mystring = "jb51.net,google.com,baidu.com_weibo.com_haotu.net" ; var myarray = mystring.split(/[,_]/); |
Hopefully this article will help you with JavaScript programming.
JS uses the Split function to split a string by multiple characters