• 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 manage NSArray, NSDictionary, ... description encoding for non ascii characters?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to manage NSArray, NSDictionary, ... description encoding for non ascii characters?


  • Subject: Re: How to manage NSArray, NSDictionary, ... description encoding for non ascii characters?
  • From: "Adam R. Maxwell" <email@hidden>
  • Date: Mon, 17 Aug 2009 18:42:58 -0700


On Aug 17, 2009, at 9:46 AM, Gernot A.Pohl wrote:

NSString *halo = @"Hello, Wörld!";
NSArray *array = [NSArray arrayWithObject:halo];
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:halo forKey:@"halo"];
NSLog(@"%@\narray=%@\ndictionary=%@", halo, array, dictionary);
/* I got on Leopard 10.5.8/Xcode 3.1.2:
2009-08-16 16:45:39.886 WhyDoWeHaveWeirdEncodingInCmdLineOut [2436:813] Hello, Wörld!
array=(
"Hello, W\U00f6rld!"
)
dictionary={
halo = "Hello, W\U00f6rld!";
}


Problem: HOW can I get the SAME NSString description output within the array/the dictionary description output???

In general, you should never rely on -description for output, since it's intended for debugging and may change between OS releases. In this case, NSDictionary and NSArray appear to be printing an old-style ASCII property list (NSPropertyListOpenStepFormat), which must use escapes for non-ASCII characters.


I need a real unicode character instead of '\U....' for a 'real' stdout in any NSString encoding but not in the given one (see my example).

You'll need to iterate the collections and print the contents yourself, or convert to XML using NSPropertyListSerialization and print that. If you need a specific encoding, use [[NSFileHandle fileHandleWithStandardOutput] writeData:[aString dataUsingEncoding:]].



Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >How to manage NSArray, NSDictionary, ... description encoding for non ascii characters? (From: Gernot A.Pohl <email@hidden>)

  • Prev by Date: Re: Mac access to iPhone Document Directory
  • Next by Date: Re: [SOLVED, with reservations] Re: Turn off menu highlight in outline view?
  • Previous by thread: How to manage NSArray, NSDictionary, ... description encoding for non ascii characters?
  • Next by thread: Mac access to iPhone Document Directory
  • Index(es):
    • Date
    • Thread