Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract 2 strings from an NSString separated by a special character

i have an NSString like "Hello - this is me". I want to search for the "-" and put the text before and after the "-" in two separate strings.

Anyone knows how to do that the best way?

greets Max

like image 551
madmax Avatar asked Apr 10 '11 20:04

madmax


1 Answers

NSString *myString = @"123-456-789-1234-2345-3456-4567";
NSArray *subStrings = [myString componentsSeparatedByString:@"-"];
for (int i = 0; i < [subStrings count]; i++) {
    NSLog(@"string on array position %d is : %@", i, [subStrings objectAtIndex:i]);
}
like image 79
Pankaj Gadhiya Avatar answered Nov 07 '22 14:11

Pankaj Gadhiya