• 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: How to construct Unicode Safe Strings in the source?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to construct Unicode Safe Strings in the source?


  • Subject: Re: How to construct Unicode Safe Strings in the source?
  • From: Manfred Lippert <email@hidden>
  • Date: Sun, 13 Jul 2003 11:59:09 +0200

--- snip ---
char * aCString = "Keld Jxrn Simonsen";
id data = [NSData dataWithBytesNoCopy: aCString length: strlen(aCString) freeWhenDone: NO];
id string = [[NSString alloc] initWithData: data encoding NSUTF8StringEncoding];
--- snap ---

An easier way to construct NSStrings from constant UTF-8 C-Strings is the following way:

NSString *string = [NSString stringWithUTF8String:"my utf8 encoded string"];

The source file must be encoded in UTF-8 of course. The returned string is autoreleased, so send it a "retain" if you need it for longer.
I don't know if this helps for your problem. I only testet this in a GUI application. But I think this should also work in a foundation tool.

Now what really mystifies me is that each of this methods to get strings with the correct content _doesn't_ work in the other project! (Though I created them both by myself and today). The only difference being that the one is a foundation tool, while the other is a GUI app. File encodings are the same (utf8) in both cases, so thats out.

_What_ does not work?
Are you sure it is not just a problem with displaying the strings?
I think Terminal uses UTF-8 by default (so it should work fine therein), but I am not sure what encoding the built in console in Project Builder uses.

Regards,
Mani
_______________________________________________
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.

  • Follow-Ups:
    • Bug in Xcode, File Inspector lies to me.. (was: Re: How to construct Unicode Safe Strings in the source?)
      • From: Martin Häcker <email@hidden>
References: 
 >How to construct Unicode Safe Strings in the source? (From: Martin Häcker <email@hidden>)

  • Prev by Date: categories question...
  • Next by Date: Re: getCString a good idea here?
  • Previous by thread: How to construct Unicode Safe Strings in the source?
  • Next by thread: Bug in Xcode, File Inspector lies to me.. (was: Re: How to construct Unicode Safe Strings in the source?)
  • Index(es):
    • Date
    • Thread