Java's spilt () function

Source: Internet
Author: User

One, single symbol as delimiter

 package   Com.regix;  public  class   funcspilt { public  static  void   main (string[] args) { /span>//  TODO auto-generated method stub  St        Ring address = "Shanghai | shanghai | Minhang | Wu zhong lu" ;  // string[] Splitaddress=address.split ("        \\|");  String splitaddress[]=address.split ("\\|"          0]+splitaddress[1]+splitaddress[2]+splitaddress[3]+    splitaddress.length); }}

Two or more symbols as separators

 Package Com.regix;  Public class funcspilt {    publicstaticvoid  main (string[] args) {           TODO auto-generated method stub         String address= "Shanghai ^ Shanghai @ Minhang # Wu Zhong Lu";        String[] splitaddress=address.split ("\\^|@|#");        System.out.println (splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]+  splitaddress.length);}    }

Summarize:

(1) The split expression is actually a regular expression. *  ^ | A symbol is a character in a regular expression that has a special meaning, and if used as a delimiter, it must be escaped with the escape character, \ \ (2) If multiple separators are used, you need to use | Symbol, as shown in two, but the escape character needs to be added to the delimiter to be processed.

Java's spilt () function

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.