Re: NSString converted into unicode
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