JS uses the Split function to segment strings by multiple characters

Source: Internet
Author: User
Tags split

This article mainly introduces JS using the Split function to split the string according to a number of characters, a case analysis of the split function of the use of skills, very practical value, the need for friends can refer to the

This article illustrates the way JS uses the Split function to segment strings according to multiple characters. Share to everyone for your reference. The specific analysis is as follows:

The split () function in JS can split the string according to the specified symbol. But if there are more than one split symbol in the string, JS split () function can also be competent, the answer is yes, JS split () function can be implemented through regular expressions of multiple separator string segmentation, The call is also simple, and the following is a detailed example.

The following code can be separated by commas by using the JS split method

?
1 2 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, and refer to the following code:

?
1 2 var mystring = "Jb51.net,google.com,baidu.com_weibo.com_haotu.net"; var myarray = Mystring.split (/[,_]/);

I hope this article will help you with your JavaScript programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.