JS uses the Split function to split a string by multiple characters

Source: Internet
Author: User

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 varmystring = "a,b,c,d,e";varmyarray = 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 varmystring = "jb51.net,google.com,baidu.com_weibo.com_haotu.net";varmyarray = mystring.split(/[,_]/);

Hopefully this article will help you with JavaScript programming.

JS uses the Split function to split a string by multiple characters

Related Article

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.