I am a beginner in iphone, and I have not learned many things, and many operations on strings are irrelevant and I do not know how to operate them.
Similar to "Rose | rose.jpg, Lily | xx.jpg, sunflower | xxx.jpg", how to obtain classification? 1) rose Lily, sunflower, 1w.rose.jpg, xx.jpg, xxx, and jpg. You can use two strings to separate them.
The following is a simple example: Obtain the number NSString * phone = "021-387126654,0579-02369865,0571-867545"; or NSString * phone = "021-387126654 ";
1) use the more complex nsange:
NSMutableString * muPhone = [[NSMutableString alloc] initWithString: phone];
Nsange range = [muPhone rangeOfString: @ ","];
Int location = range. location;
Int length = range. length;
// When you still need to judge that there is only one phone number, that is, no. When multiple phone numbers are separated, this method will fail if you do not make the following judgment.
If (0 = length ){
Self. rPhone = phone;
} Else {
Self. rPhone = [phone substringToIndex: location];
}
2) use the string segmentation method (this method does not need to be like 1) and need to be judged ):
NSArray * phones = [phone componentsSeparatedByString: @ ""]; // ** string segmentation **
// You only need to determine if phones. count is> 0. Obtain the following 1st phone numbers.
Self. rPhone = [phones objectAtIndex: 0];
// Obtain multiple phone numbers
For (NSString * p in phones ){
Self. rPhone = p;
}
You can use a similar method to obtain the desired string from a string.
Below are some of the links that I have found by my predecessors to better summarize string operations. I would like to make a memo here for the future:
Http://xiaozu.renren.com/xiaozu/218897/333605171 Iphone array some basic operations NSArray/NSMutableArray;
Http://www.wangdg.com /? P = 123 Summary of NSString processing;
Search string truncation extraction for http://blog.csdn.net/houchangxi/article/details/6760158 NSString.