how can I convert string to an array with separator?

后端 未结 12 1958
故里飘歌
故里飘歌 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条回答
  •  萌比男神i
    2020-12-09 07:39

    componentsSeparatedByString: splits the string and return the result in an array.

    NSArray *myArray = [myString componentsSeparatedByString:@"+"];
    
    [myArray objectAtIndex:0];//cat
    [myArray objectAtIndex:1];//dog
    [myArray objectAtIndex:2];//cow
    

提交回复
热议问题