Extract 2 strings from an NSString separated by a special character

后端 未结 2 1263
情歌与酒
情歌与酒 2021-02-05 17:39

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 d

2条回答
  •  忘掉有多难
    2021-02-05 18:08

    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]);
    }
    

提交回复
热议问题