views:

1463

answers:

1

I want to split a long string received from a server to a few substrings. The separate characters are different.

Are there any sample code for method: componentsSeparatedByCharactersInSet? Or may I ask a simple code to split "A~B^C" to "A", "B" and "C"?

+2  A: 

Try this

NSString *str = @"A~B^C";

NSArray *arr = [str componentsSeparatedByCharactersInSet:
          [NSCharacterSet characterSetWithCharactersInString:@"^~"]];

NSLog(@"%@", arr);
epatel
Thanks indeed. Is NSLog just a log? Must I use the Log every time I deal with an array?
iPhoney
It's just a log to show the elements in the array, it should write A, B, C seperate
epatel