Android--split () Split string special usage

Source: Internet
Author: User

Tags: differentiate nbsp expression analysis span character androi and;;

Split () split string1. Distinctions in different environments

Java: The split string cannot be written as split ("$")//$ as the character to be split
Android: Split string needs to be combined with brackets split ("[$]")//$ for the character to be split

2. Special usage--when split () split string encounters special symbolsCase Analysis
1   String str = "ABC|DFG"; 2 3 string[] All=str.split ("|") ); 4 5 System.out.println (all[0]); 6 7 result for  a

Cause analysis

| In the regular expression is a special symbol (".", "|", "^") that has been used.

So want to use | , it must be escaped with \, and in the Java string, \ is a special symbol that has already been used, and it needs to be escaped using \.

Therefore, the following should be: string[] All=str.split ("\\|") ;

Android--split () Split string special usage

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: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: