Skip navigation.
 
mlPercent Encoding Url Components
FROM : John Cassington
DATE : Thu Apr 26 22:58:01 2007

Hi, I have a string containing a URL address which itself has a URL
component as shown:

http://www.google.com/search?q=COMPONENT

This component is simply an NSString
<http://cocoadev.com/index.pl?NSString>which i need to percent escape
before posting. An example of the components
contents is as follows:

'cocoadev rocks!'

I have attempted to replace the space and exclamation mark with their
respective percent-escaped values, %20 and %21 respectively.

Here is my code so far, which has not been working:

- (NSString <http://cocoadev.com/index.pl?NSString>
*)urlEncodeValue:(NSString <http://cocoadev.com/index.pl?NSString>
*)string {
   CFStringRef <http://cocoadev.com/index.pl?CFStringRef>
originalURLString = (CFStringRef
<http://cocoadev.com/index.pl?CFStringRef>)string;
   CFStringRef <http://cocoadev.com/index.pl?CFStringRef>
preprocessedString =
CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
originalURLString, CFSTR(""), kCFStringEncodingUTF8);
   CFStringRef <http://cocoadev.com/index.pl?CFStringRef>  urlString =
CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
preprocessedString, NULL, NULL, kCFStringEncodingUTF8);
   return (NSString <http://cocoadev.com/index.pl?NSString>  *)urlString;
}

I have also tried the following

- (NSString <http://cocoadev.com/index.pl?NSString>
*)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding

but that method doesn't seem to encode all values, such as ! and + etc.

any ideas as to why this isn't working
thanks,

john

Related mailsAuthorDate
mlPercent Encoding Url Components John Cassington Apr 26, 22:58
mlRe: Percent Encoding Url Components Jerry Krinock Apr 26, 23:25