• 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: String conversion help.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String conversion help.


  • Subject: Re: String conversion help.
  • From: Ali Ozer <email@hidden>
  • Date: Thu, 23 Jun 2005 08:03:13 -0700

In NSString APIs all references to "characters" is UTF-16, in native endianness.

So initWithCharacters:... and getCharacters: should have worked for you, at least for big endian data on the PowerPC.

However, if the characters are not native endianness, it's best to use one of the encoding methods joar points out.

Ali



Begin forwarded message:

From: j o a r <email@hidden>
Date: June 23, 2005 0:15:52 PDT
To: John Draper <email@hidden>
Cc: email@hidden
Subject: Re: String conversion help.



On 23 jun 2005, at 09.03, John Draper wrote:


I know that NSString has "stringWithUTF8String" class methods, but
I don't see any class methods that can construct a NSString,  given
a pointer to a buffer of characters of 16 bits in length (u_shorts)
or what I believe to be UTF16 type string encodings.


NSStringEncoding *strEncoding = CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingUTF16);


NSString *aStr = [[NSString alloc] initWithBytes: myStrData length: myStrLen encoding: strEncoding];

Note that this encoding type was added with Mac OS X 10.4.


I also want to be able to go the other way... IE: Given an NSString,
and a pointer to a buffer big enough to hold it, return the data in
UTF16 encoding in the buffer. Obviously, the buffer allocated would have
to be twice the size of the string plus 2 more bytes for the NULL at
the end.



const void *strBuf = [[aStr dataUsingEncoding: strEncoding] bytes];

j o a r


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: String conversion help.
      • From: John Draper <email@hidden>
References: 
 >String conversion help. (From: John Draper <email@hidden>)
 >Re: String conversion help. (From: j o a r <email@hidden>)

  • Prev by Date: Re: CoreData: get/set methods in undo and flushing of caches
  • Next by Date: Re: NSConnection not working between processes
  • Previous by thread: Re: String conversion help.
  • Next by thread: Re: String conversion help.
  • Index(es):
    • Date
    • Thread