How do I insert a space to a NSString.
I need to add a space at index 5 into:
NString * dir = @"abcdefghijklmno";
To get this result:
abcde fghijklmno
with:
NSLOG (@"%@", dir);
You need to use NSMutableString
NSMutableString *mu = [NSMutableString stringWithString:dir]; [mu insertString:@" " atIndex:5];
or you could use those method to split your string :
– substringFromIndex:
– substringWithRange:
– substringToIndex:
and recombine them after with
– stringByAppendingFormat:
– stringByAppendingString:
– stringByPaddingToLength:withString:startingAtIndex:
http://stackoverflow.com/questions/8722051/how-to-insert-a-character-into-a-nsstring