Splitting a string using symbols in Objective C

By | March 20, 2011

Hi,
If you want to split a string between a symbol like, ‘.’ or ‘-‘ or ‘,’ in Objective C, what to do?
See the code for how to split string in Objective C.

NSString *myString = @โ€song.mp3โ€;
NSArray *splitArray = [myString componentsSeparatedByString:@โ€.โ€];

This code will split the string ‘myString’ into ‘song’ & ‘mp3’ (separated by ‘.’) and stores in the splitArray indices 0 & 1 respectively.
๐Ÿ™‚

One thought on “Splitting a string using symbols in Objective C

Leave a Reply

Your email address will not be published. Required fields are marked *