• 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: Glyph's
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Glyph's


  • Subject: Re: Glyph's
  • From: Chris Ridd <email@hidden>
  • Date: Sun, 27 Apr 2003 15:00:31 +0100

On 27/4/03 11:03 am, Mathew Peterson <email@hidden> wrote:

> I have an old file (I assume encoded in NSMacOSRomanStringEncoding)
> that I need to decode into something I can use in Cocoa (particularly a
> string).
>
> Now I have this code:
>
> [stringOut setStringValue:[[[NSString alloc] autorelease]
> initWithData:[[NSString stringWithFormat:@"ElE4E0Gh"]
> dataUsingEncoding:NSMacOSRomanStringEncoding]
> encoding:NSUnicodeStringEncoding]];
>
> Which is a fragment of Glyph which spells out some Japanese characters.
> I know the file is NSMacOSRomanStringEncoding because when I set my
> string value with encoding NSUTF8StringEncoding it produces my glyph's.
> I cannot for the life of me though get those Japanese characters to
> display in their proper Unicode format. Btw, that glyph is KoNiChiWa
> encoded.
>
> Can anyone assist me?

You can only create static NSStrings using the @"..." construct if they are
7-bit US-ASCII strings. I'm not sure if you were expecting to be able to put
MacOSRoman-encoded characters in there or not; they didn't survive being
emailed.

There's no way to create truly static strings of arbitrary Unicode
characters, but there are a couple of workarounds that get you close:

1) calculate the UTF-8 encoding of your Unicode string, and use [NSString
stringWithUTF8String:]

2) build your string in an array of unichar, and then use [NSString
stringWithCharacters:length:]

3) build your string in an array of char, wrap it in an NSData and use
NSString's initWithData:encoding: to get an NSString.

Cheers,

Chris
_______________________________________________
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: 
 >Glyph's (From: Mathew Peterson <email@hidden>)

  • Prev by Date: Treating bundles like directories in NSOpenPanel?
  • Next by Date: Re: converting text input in any encoding to unicode
  • Previous by thread: Glyph's
  • Next by thread: RE: Glyph's
  • Index(es):
    • Date
    • Thread