• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Percent Encoding Url Components
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Percent Encoding Url Components
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: Re: Preserving user interface properties in Core Data documents
  • Next by Date: Re: NSArray - waste of time?
  • Previous by thread: Re: Preserving user interface properties in Core Data documents
  • Next by thread: Re: Percent Encoding Url Components
  • Index(es):
    • Date
    • Thread