Re: stringWithCString vs stringWithUTF8String
Re: stringWithCString vs stringWithUTF8String
- Subject: Re: stringWithCString vs stringWithUTF8String
- From: Jim Correia <email@hidden>
- Date: Mon, 4 Nov 2002 13:25:32 -0500
On Monday, November 4, 2002, at 01:09 PM, Brian Redman wrote:
I've got some email text I read from a pop server. According to the
header it's:
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
When I create an NSString from the char* text using
stringWithUTF8String I get nil. If I use stringWithCString it works.
I get an NSString containing my text.
If I want to avoid stringWithCstring what method(s) should I be using
to create the NSString from this text? I read through the NSString
encoding material but I really don't get it.
Up until now replacing all my CStrings with UTF8Strings has worked
transparently.
stringWithCString and stringWithUTF8String are not interchangeable.
Use stringWithCString when you have a string in the system default
encoding (or ascii). Since you don't know what the system default
encoding is, it isn't something you want to use if it can be avoided.
Use stringWithUTF8String when you have a utf8 encoded string. When you
don't, you cannot use it.
If you know the encoding, like you do in your example, you must use the
appropriate encoding. Blindly using UTF8 when the input is not will not
work.
Jim
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.