Re: String conversion help.
Re: String conversion help.
- Subject: Re: String conversion help.
- From: John Draper <email@hidden>
- Date: Thu, 23 Jun 2005 13:10:09 -0700
j o a r wrote:
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.
Darn - you are saying this only works with 10.4? My requirement is my
application has to run
on 10.3 or greater. This is a requirement.
If this is only good on 10.4 systems, is there an alternative?
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];
WOW! Sounds simple enough - I just hope I can get this to work on 10.3
systems.
John
_______________________________________________
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