Xcode: split 的用法

NSString *str = @"011597464952,01521545545,454545474,454545444|Hello this is were the message is."; 

NSArray *firstSplit = [str componentsSeparatedByString:@"|"]; 
NSAssert(firstSplit.count == 2, @"Oops! Parsed string had more than one |, no message or no numbers."); 
NSString *msg = [firstSplit lastObject]; 
NSArray *numbers = [[firstSplit objectAtIndex:0] componentsSepratedByString:@","]; 

// print out the numbers (as strings) 
for(NSString *currentNumberString in number) { 
NSLog(@"Number: %@", currentNumberString); 
} 

猜你喜欢

转载自blog.csdn.net/lbuskeep/article/details/39204943