Check the stringByReplacingOccurrencesOfString: withString: on NSString method if you just want to replace the characters in the string with a different value.
Returns a new line in which all occurrences of the target line in the receiver are replaced by another specified line.
NSString *originalString = @"Sample text with spaces"; NSString *newString = [originalString stringByReplacingOccurancesOfString:@" " withString:@"%20"];
If you are trying to encode a URL, use stringByAddingPercentEscapesUsingEncoding: on NSString .
Returns the representation of the recipient using the specified encoding to determine the percentage screens required to convert the recipient to the legal URL string.
NSString *originalString = @"Sample text with spaces"; NSString *newString = [originalString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Dan
source share