• 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: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >NSString encoding problem with extended characters ( AKA : converting NSString to std::string) (From: Alexander Hartner <email@hidden>)

  • Prev by Date: Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
  • Next by Date: Re: NSDatePicker behaviour is odd when typing date
  • Previous by thread: Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
  • Next by thread: Re: NSString encoding problem with extended characters ( AKA : converting NSString to std::string)
  • Index(es):
    • Date
    • Thread