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];


_______________________________________________ Help-gnustep mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/help-gnustep

Reply via email to