hey all i want a code the replace whitespaces by a + sign in objective-c
Use the replaceAll() method to replace a character with a space. The method takes the character to be replaced and the replacement string as parameters, e.g. str. replaceAll('_', ' ') . The method returns a new string with all occurrences of the character replaced by the provided replacement.
Use the String. replace() method to replace all spaces in a string, e.g. str. replace(/ /g, '+'); . The replace() method will return a new string with all spaces replaced by the provided replacement.
In case you are asking this because you need to encode URLs, use this
NSString* escapedUrlString =
[unescapedString stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
If you just need space to +, use
[str stringByReplacingOccurrencesOfString:@" " withString:@"+"];
return [thatString stringByReplacingOccurrencesOfString:@" " withString:@"+"];
If your real target is to escape URL component, use the -stringByAddingPercentEscapesUsingEncoding:
method instead.
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