Istorn Istorn - 1 year ago 78
Swift Question

Split string by particular character objective-c

I have a string structured in this way:


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

Answer Source
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download