itsaboutcode
itsaboutcode

Reputation: 25099

How to convert cstring to NSString and NSString to cstring?

Lets say i have the following cstring

char array[1000];

How i can convert it to NSString and vice verse.

Thanks.

Upvotes: 3

Views: 4289

Answers (1)

Jorge Israel Peña
Jorge Israel Peña

Reputation: 38586

Apple's Developer Reference has a good article on this subject. Basically, you will do something like this:

NSString *stringFromUTFString = [[NSString alloc] initWithUTF8String:utf8String];

if the string is UTF8 encoded. Otherwise, you can use initWithCString:encoding: with which you can specify the encoding.

Here is a list of available string encodings.

Upvotes: 11

Related Questions