• 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
Converting C strings into NSStrings (and vice versa)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Converting C strings into NSStrings (and vice versa)


  • Subject: Converting C strings into NSStrings (and vice versa)
  • From: Paolo Bertani <email@hidden>
  • Date: Thu, 27 Apr 2006 16:38:47 +0200

From a text file produced on a Windows machine I generate null- terminated c strings.

Then I need to convert those strings into NSStrings.

I have:

char *cString;

I use:

NSString *s = [NSString stringWithCString:cstring encoding:kTextEncodingWindowsANSI];

Unfortunately if the c string contains characters like uppercase accented U (this is how it appears on Mac, on PC it's a lowercase accented u) the method returns nil!



I have similar troubles doing the reverse process: if some characters cannot be represented with the given encoding the method gives up.
For the conversion NSString -> c string now I'm using the deprecated getCString:maxLength:



What are the correct methods I should use?
I just want to have best possible c representation of the given NSString and vice-versa.



Thank you.

Paolo.




_______________________________________________ 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: Converting C strings into NSStrings (and vice versa)
      • From: Kenny Leung <email@hidden>
    • Re: Converting C strings into NSStrings (and vice versa)
      • From: Ondra Cada <email@hidden>
    • Re: Converting C strings into NSStrings (and vice versa)
      • From: Tito Ciuro <email@hidden>
  • Prev by Date: New Dictionary
  • Next by Date: Re: New Dictionary
  • Previous by thread: Re: New Dictionary
  • Next by thread: Re: Converting C strings into NSStrings (and vice versa)
  • Index(es):
    • Date
    • Thread