Split using the split Function

Source: Internet
Author: User

1. When multiple spaces exist, the following conditions are met:

String S = "keyword"; string [] array = S. split ("\ s +"); For (string L: array) {system. out. println (L + "");}

\ S indicates space, carriage return, line feed, and other blank characters. + indicates one or more spaces.

Extended, \ D represents 0-9 numbers; \ W represents characters, numbers, letters or underscores;

These are Java Regular Expressions


2. When there are multiple delimiters:

String S = "I love you, mother! "; String [] arraytemp = S. Split (" |, "); For (string L: arraytemp) {system. Out. println (L + "");}

Add a vertical line in the middle to split multiple separators.

3. When used | ,[,\,.,*,? , And other special characters to be separated, escape, such as S. Split ("\ | ");

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.