how can I convert string to an array with separator?

后端 未结 12 1979
故里飘歌
故里飘歌 2020-12-09 07:26

I have a string in the following format

myString = \"cat+dog+cow\"

I need to store each string separated by + in to a array. Eg:



        
12条回答
  •  情话喂你
    2020-12-09 07:34

    Simple code :

    NSString *myString = [[NSString alloc] initWithString:@"cat+dog+cow"];
    NSArray *resultArray = [tempString componentsSeparatedByString:@"+"];
    
    NSLog(@"1. %@ 2. %@ 3. %@",[resultArray objectAtIndex:0],[resultArray objectAtIndex:1],[resultArray objectAtIndex:2]);
    

提交回复
热议问题