Re: Str255 Conversion
Re: Str255 Conversion
- Subject: Re: Str255 Conversion
- From: "Clark S. Cox III" <email@hidden>
- Date: Wed, 12 Mar 2003 15:21:27 -0500
On Wednesday, Mar 12, 2003, at 14:12 US/Eastern, Craig Bakalian wrote:
Hi,
I need to convert a Str255 to an NSString. I am using voice
recognition. All is well, except for the Str255. How do I do it? What
exactly is a Str255? I mean, I thought I knew everything :) Thanks in
advance...
A Str255 is an array of 256 unsigned chars, the first of which
represents the length of the string (i.e. it's a pascal-style string).
If you know for a fact that it doesn't contain any non-ASCII characters:
Str255 somePascalString = "\pMy string";
NSString *nsString = [NSString stringWithCString: (const
char*)&somePascalString[1] length: somePascalString[0]];
Or, since CFStrings and NSStrings are identical, you could do something
along the lines of (replace kCFStringEncodingMacRoman with the
appropriate encoding):
Str255 somePascalString = "\pMy string";
NSString *nsString = [(NSString*)CFStringCreateWithPascalString(NULL,
somePascalString, kCFStringEncodingMacRoman) autorelease];
--
http://homepage.mac.com/clarkcox3/
email@hidden
Clark S. Cox, III
_______________________________________________
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.