how can I convert string to an array with separator?

后端 未结 12 1988
故里飘歌
故里飘歌 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:56

    Use the componentsSeparatedByString: method of NSString.

     NSString string = @"hai-welcome";
     NSArray myArray = [string componentsSeparatedByString:@"-"];
    
    NSString* haiString = [myArray objectAtIndex:0];
    NSString* welcomeString = [myArray objectAtIndex:1];
    

提交回复
热议问题