Istorn Istorn - 2 months ago 7
iOS Question

Split string by particular character ,iOS

I have a string structured in this way:


What's the best method to obtain three distinct strings through the position of sharps?

NSString *str=@"Description#Data#IMG";  //is your str

NSArray *items = [str componentsSeparatedByString:@"#"];   //take the one array for split the string

NSString *str1=[items objectAtIndex:0];   //shows Description
NSString *str2=[items objectAtIndex:1];   //Shows Data
NSString *str3=[items objectAtIndex:2];   // shows IMG

Finally NSLog(@"your  3 stirs ==%@   %@  %@", str1, str2, str3);


 //is your str  
 var str: String = "Description#Data#IMG"

var items: [AnyObject] = str.componentsSeparatedByString("#") //take the one array for split the string
var str1: String = items.objectAtIndex(0)    //shows Description
var str2: String = items.objectAtIndex(1)    //Shows Data
var str3: String = items.objectAtIndex(2) // shows IMG