How to split string into substrings on iOS?

Chilly Zhong picture Chilly Zhong · Feb 27, 2009 · Viewed 99.4k times · Source

I received an NSString from the server. Now I want to split it into the substring which I need. How to split the string?

For example:

substring1:read from the second character to 5th character

substring2:read 10 characters from the 6th character.


codelogic picture codelogic · Feb 27, 2009

You can also split a string by a substring, using NString's componentsSeparatedByString method.

Example from documentation:

NSString *list = @"Norman, Stanley, Fletcher";
NSArray *listItems = [list componentsSeparatedByString:@", "];