Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Percent Encoding Url Components



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
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.