Detailed explanation of special usage cases of split() string segmentation in Android

Split() split string

1. Differentiation under different environments

Java: split string cannot be written as split ("$") / / $as the character to be split

Android: split ("[$]") / / $is the character to be split

2. Special usage -- when split() splits a string and encounters a special symbol

case analysis

The result is a

Cause analysis

|In regular expressions, it is a special symbol that has been used (".", "|", "^" and other characters). Therefore, if you want to use |, you must use \ to escape. In Java strings, \ is also a special symbol that has been used, and you also need to use \ to escape.

So it should be: String [] all = str.split ("\ \ |);

The above is the special usage of split() string segmentation in Android introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>