Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
- Subject: Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
- From: "Clark Cox" <email@hidden>
- Date: Mon, 19 Mar 2007 18:54:50 -0700
On 3/19/07, Alexander Hartner <email@hidden> wrote:
I am obtaining a NSString from the iSync API via :
[changeRecord objectForKey:@"first name"]
and I am trying to convert this string into a std::string. I tried
using :
std::string * firstName = new std::string([[changeRecord
objectForKey:@"first name"] UTF8String]);
This is the only reasonable way to do it without losing data.
which seems to work in most cases, however sometime the string
contains characters from the extended character set (>127).
You'll have to define "work".
[snip]
NSString * two = @"Björn";
The @"..." syntax does not support non-ASCII characters. In a real
program, I would recommend using strings loaded from *.strings files.
But since this is a throwaway test program, use this:
NSString *two = [NSString stringWithUTF8String: "Bj\xC3\xB6rn"];
{
const char * chars = [two UTF8String];
int index = 0;
while (chars[index] != nil)
{
cout << index << " : " << chars[index] << endl;
index ++;
}
}
--
Clark S. Cox III
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden