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 *