• 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: j o a r <email@hidden>
  • Date: Thu, 23 Jun 2005 09:15:52 +0200


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


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

 _______________________________________________
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>
    • Re: String conversion help.
      • From: Ali Ozer <email@hidden>
References: 
 >String conversion help. (From: John Draper <email@hidden>)

  • Prev by Date: Link C library in Cocoa.
  • Next by Date: Re: NSConnection not working between processes
  • Previous by thread: String conversion help.
  • Next by thread: Re: String conversion help.
  • Index(es):
    • Date
    • Thread