Percent Encoding Url Components
Percent Encoding Url Components
- Subject: Percent Encoding Url Components
- From: "John Cassington" <email@hidden>
- Date: Fri, 27 Apr 2007 06:58:01 +1000
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, and ! 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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden