How to replace spaces with a +

Hi everyone, I want the code to replace spaces with a + sign in objective-c

+4
source share
2 answers

If you ask about this because you need to encode urls, use this

NSString* escapedUrlString = [unescapedString stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]; 

If you just need a place for +, use

 [str stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 
+16
source
 return [thatString stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 

If your real goal is to avoid the url component, use the -stringByAddingPercentEscapesUsingEncoding: method -stringByAddingPercentEscapesUsingEncoding: .

+1
source

All Articles