I need to add space after every 4 characters in a string.. For example if the string is aaaaaaaa, i need to format it as aaaa aaaa. I tried the following code, but it doesn’t work for me.
NSMutableString *currentFormattedString = [[NSMutableString alloc] initWithString:formattedString];
int count = [formattedString length];
for (int i = 0; i<count; i++) {
if ( i %4 == 0) {
[currentFormattedString insertString:@" " atIndex:i];
}
}
Can anyone help me with this?
I found the following which formats a string to a telephone number format, but it looks like you could easily change it to support other formats
Telephone number string formatting