[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: encoding to latin2
From: |
Richard Frith-Macdonald |
Subject: |
Re: encoding to latin2 |
Date: |
Thu, 26 Jun 2003 12:53:21 +0100 |
On Thursday, June 26, 2003, at 10:50 am, reuss wrote:
I am unable to convert the following
legyõz
to latin2 string
with dataUsingEncoding:9?
I would like to put in an NSDictionary, but I got the message:
Uncaught exception NSInvalidArgumentException, reason: Tried to add nil
That means the string you were trying to convert to latin2 contained
characters which can't be represented in the latin2 encoding.
Most likely you specified an illegal string to start with ... the
common mistake is to put non-ascii characters in a string literal ...
literal strings of the form @"my string" may only contain ascii
characters so writing @"legyõz" would be illegal and would cause
problems.
To get non-ascii data into a string, you could do something like -
NSData *d = [NSData dataWithBytes: "legyõz" length: 6];
NSString s = AUTORELEASE([[NSString alloc] initWithData: d encoding:
NSLatin2StringEncoding]);
or you could encode it as unicode data in a literal propertylist string
by using the \UXXXX convention to specify a sixteen bit unicode
character as a using a hexadecimal value (I don't know the unicode for
õ, but you see what I mean) ...
s = [@"legy\UXXXXz" propertyList];