• 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
Re: NSString converted into unicode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString converted into unicode


  • Subject: Re: NSString converted into unicode
  • From: Carl Johan Foss <email@hidden>
  • Date: Sun, 12 Nov 2006 16:38:19 +0100

Tack!
Agree, that was something I thought existed.

Well the string I have is used for is an API that did not accept my special characters. The code I used below solved it though.


- (NSString *)URLEncodingOfString:(NSString *)s
{
return (NSString *)CFURLCreateStringByAddingPercentEscapes (kCFAllocatorDefault, (CFStringRef)s, NULL, NULL, kCFStringEncodingISOLatin1);
}


Then passing that that into [NSURL URLWIthString:(NSString*)]


On Nov 12, 2006, at 4:22 PM, j o a r wrote:

Hej,

On 12 nov 2006, at 11.13, Carl Johan Foss wrote:

I was wondering if anybody can give me a hint on how to convert an
NSString which contains å ä ö characters into a unicode string

Just for the record, the internal representation of NSString is Unicode, so no conversion is required if that's all that you need. You can actually consider an NSString to be "without encoding", as the encoding is only really interesting when import / export characters from / to APIs that doesn't accept NS/CFStrings.


In this case what you really want to do is to create a representation that is valid for a URL, according to RFC 2396. When you think about it, it's actually a bit weird that NSURL doesn't provide this type of functionality as an option when creating instances from NSStrings. It seems that something like this would make sense:

+[NSURL URLWithString:(NSString *) string encoding: (NSStringEncoding)encoding]

The current way to create an NSURL from an NSString - sometimes requiring you to create an intermediary NSString with pre-converted characters - seems a bit backward. I've filed a case with Apple about that.


On 12 nov 2006, at 11.28, Dmitry Savenok wrote:

try CFURLCreateStringByAddingPercentEscapes

There is also:

-[NSString stringByAddingPercentEscapesUsingEncoding: (NSStringEncoding)encoding]


j o a r



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >NSString converted into unicode (From: "Carl Johan Foss" <email@hidden>)
 >Re: NSString converted into unicode (From: "Dmitry Savenok" <email@hidden>)
 >Re: NSString converted into unicode (From: j o a r <email@hidden>)

  • Prev by Date: NSColor to CGColor
  • Next by Date: Re: NSColor to CGColor
  • Previous by thread: Re: NSString converted into unicode
  • Next by thread: Finder like search query UI elements
  • Index(es):
    • Date
    • Thread