Special usage of Android -- split () to split strings, csplit to separate strings

Source: Internet
Author: User

Special usage of Android -- split () to split strings, csplit to separate strings
Split () split string 1. Differentiation in different environments

Java: The split string cannot be written as split ("$") // $ is the character to be split.
Android: The split string must contain brackets ("[$]"). // $ indicates the character to be split.

2. Special usage -- Case Study of split () character strings in special characters
 
1 String str = "abc | dfg"; 2 3 String [] all = str. split ("|"); 4 5 system. out. println (all [0]); 6 7 returns

 

Cause Analysis

| A regular expression is a special character (".", "|", "^", and so on) that has been used)

To use |, you must use \ for escape. In java strings, \ is also a special symbol that has been used and must be escaped using.

So it should be: String [] all = str. 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.