I'm looking for a good way in Objective-C to replace the last comma in a string with the word "and". Any suggestions?
"Red, Green, Blue, Yellow"
becomes
"Red, Green, Blue and Yellow"
NSString *str = @"...."; NSRange lastComma = [str rangeOfString:@"," options:NSBackwardsSearch]; if(lastComma.location != NSNotFound) { str = [str stringByReplacingCharactersInRange:lastComma withString: @" and"]; }
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