• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: foundation kit (help i'm new to cocoa)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: foundation kit (help i'm new to cocoa)


  • Subject: Re: foundation kit (help i'm new to cocoa)
  • From: Mike Ferris <email@hidden>
  • Date: Mon, 6 Jan 2003 09:01:13 -0800

-UTF8String is good if UTF8 is the encoding you want.

-cString is bad because it uses the "default" encoding which can be different for different users and therefore you wind up in a situation where it will fail for some users with the same string that worked for other users.

-lossyCString will convert to the default encoding and will not choke if the conversion cannot be done because of some of the characters in the string (you'll get a substitute character ('?' I think) for any unicodes that cannot be converted to the default encoding.

If your string contains only ASCII characters (ie Unicodes from 0x0001-0x007F) then any of these methods will give the same answer.

In general, some thought is required when your app needs to convert NSStrings to (char *) data. If you can avoid it, don't do it. If you have to, think about the encoding issues (preferrably as a global design point of your app... think about how your app as a whole needs to deal with textual data and be consistent throughout). And, my own opinion is that if you can use UTF-8 as the encoding when dealing with textual data, you should. It is usually a better choice for a number of reasons. But if you're dealing with another subsystem that expects a specific encoding, you may not have that choice.

Mike
_______________________________________________
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.

References: 
 >Re: foundation kit (help i'm new to cocoa) (From: Quentin Mathé <email@hidden>)

  • Prev by Date: Re: Making iTunes-style NSTableView
  • Next by Date: what #ifdef's should I use?
  • Previous by thread: Re: foundation kit (help i'm new to cocoa)
  • Next by thread: Loading a Text File into an NSTextView
  • Index(es):
    • Date
    • Thread