How to convert an NSString to Char and vice versa

I have a lot of code written in C, since I'm writing code for the iPhone the need of reusing this old code has arisen.

One of the first thing to do is the conversion between NSString and char *

you can convert NSString to char* simply using the following line of code:

const char *myString = [myNSString UTF8String];

and viceversa

NSString *myNSString  = [NSString stringWithUTF8String:myString];

 

 

 

If you found useful this article, please share it using the social buttons below. Thank you in advance,

Gg1.

Posted by at October 17, 2010
Filed in category: iphone, Mac OS X, The Prince: C, Tower of Babel, xAppSoftware News, and tagged with: , , , , ,

One Response to How to convert an NSString to Char and vice versa

  1. Pingback: The five best posts of the second semester of the 2011 | xAppSoftware Blog

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

%d bloggers like this: