In Java, there are many ways to manipulate strings, and you can do so by importing the appropriate string-handling Lib package. But today is the two ways to deal with strings that you see on Android.
First, regular expression
In fact, the regular expression is not as difficult as everyone think (although I have to check the data to write), it is like a word game, the rules are placed there, we just remember the rules can let us free play.
As for what is regular expression, I do not popularize the basic knowledge here, this online tutorial really a lot, you can see here http://blog.csdn.net/luosijin123/article/details/4792181
The General Java notation
Pattern pattern; // compiler Matcher Matcher; // Matching device Pattern = Pattern.compile (". *cpacm.*"); // The regular expression to be compiled is placed in the compiler, which means matching all strings that contain the CPACM field Matcher = Pattern.matcher (p); // to see if a string matches by a matching device if (Matcher.matches ()) {// match return true ; } return false;
Very simple
Second, textutils
This class I found in Android, I do not know whether Java itself to bring this class. Its function is simple, which is to handle strings for you, including:
- Find the position of a character in a string
- The
- Create a child string
- String segmentation
- Determines whether the empty
- String inversion
- Rewrite one of these little pieces
And so on, these are commonly used string operations, the details can look at the source code or API http://www.apihome.cn/api/android/TextUtils.html
The source code is in Android.text.TextUtils.
Android simple Application (iv)--string processing