What is the simplest way to split an NSString by the maximum number of characters?
For example, if I have a string that is 204
characters long and I want to split it at 100
characters, it should yield an NSArray with three substrings (100,100,4
).
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]];
Don't forget to release the array when you have done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With