Divide NSString by number of characters?

What is the easiest way to split NSString by maximum number of characters?

For example, if I have a string length of 204 , and I want to split it into 100 characters, it should give an NSArray with three substrings ( 100,100,4 ).

+4
source share
1 answer
 NSMutableArray *array = [[NSMutableArray alloc] init]; int len=0; while( (len+100)<[string length]) { [array addObject:[string substringWithRange:NSMakeRange(len,100)]]; len+=100; } [array addObject:[string substringFromIndex:len]]; 

Remember to free the array when you do this.

+7
source

All Articles