Java String.Split () the point of attention when splitting special characters

Source: Internet
Author: User

"1" single symbol as delimiter         string address= "Shanghai | shanghai | Minhang | Wu Zhong Lu";      string[] Splitaddress=address.split ("\\|"); If you use a vertical bar as a delimiter, you need to add two slashes "\ \" to escape      system.out.println when split (splitaddress[0]+ SPLITADDRESS[1]+SPLITADDRESS[2]+SPLITADDRESS[3]);              string address= "Shanghai * Shanghai * Minhang * Wu Zhong Lu";      string[] splitaddress= Address.split ("\\*");      system.out.println (splitaddress[0]+splitaddress[1]+ SPLITADDRESS[2]+SPLITADDRESS[3]);             String address=, Shanghai: Shanghai: Minhang: Wu Zhong Lu;      string[] splitaddress=address.split ("\ \:");      system.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);           string address= "Shanghai, Shanghai Minhang. Wu Zhong Lu"; &nbSp;    string[] Splitaddress=address.split ("\ \");      system.out.println (splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[ 3]);            string address= "Shanghai ^ Shanghai ^ Minhang ^ Wu Zhong Lu";      string[] Splitaddress=address.split ("\\^");      System.out.println (splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);               string address= "Shanghai @ Shanghai @ Minhang @ Wu Zhong Road";      string[] Splitaddress=address.split ("@");      system.out.println ( SPLITADDRESS[0]+SPLITADDRESS[1]+SPLITADDRESS[2]+SPLITADDRESS[3]);         string address= "Shanghai, Shanghai, Minhang, Wu Zhong Road";      string[] Splitaddress=address.split (",");      system.out.println (splitaddress[0]+splitaddress[1]+SPLITADDRESS[2]+SPLITADDRESS[3]);       "2" multiple symbols as separators        string address= "Shanghai ^ Shanghai @ Minhang # Wu Zhong Lu";      string[] Splitaddress=address.split ("\ \^|@|# ");      system.out.println (splitaddress[0]+splitaddress[1]+splitaddress[2]+ SPLITADDRESS[3]);      ***************************Formatting TipsString address = new String ("192.168.13.240");        string[] str = address.split ("\ \");        for (String s:str) {System.out.println (s); }output Format:19216813240system.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);output Format:***************************************************************** Summary of Wuzhong Road, Minhang, Shanghai, Shanghai, China: (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 | Symbols, as shown in "2", but the escape character needs to be added to the delimiter to be processed.

Java String.Split () the point of attention when splitting special characters

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.