Converting C strings into NSStrings (and vice versa)
Converting C strings into NSStrings (and vice versa)
- Subject: Converting C strings into NSStrings (and vice versa)
- From: Paolo Bertani <email@hidden>
- Date: Thu, 27 Apr 2006 16:38:47 +0200
From a text file produced on a Windows machine I generate null-
terminated c strings.
Then I need to convert those strings into NSStrings.
I have:
char *cString;
I use:
NSString *s = [NSString stringWithCString:cstring
encoding:kTextEncodingWindowsANSI];
Unfortunately if the c string contains characters like uppercase
accented U (this is how it appears on Mac, on PC it's a lowercase
accented u) the method returns nil!
I have similar troubles doing the reverse process: if some characters
cannot be represented with the given encoding the method gives up.
For the conversion NSString -> c string now I'm using the deprecated
getCString:maxLength:
What are the correct methods I should use?
I just want to have best possible c representation of the given
NSString and vice-versa.
Thank you.
Paolo.
_______________________________________________
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