SimplyKiwi
SimplyKiwi

Reputation: 12444

Convert NSString to UTF8String?

Currently I am download data from a server and I have this line to get that NSData into a NSString.

NSString *txt = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

How would I go from here to convert that NSString into a UTF8 string?

Thanks!

Upvotes: 3

Views: 11396

Answers (2)

Simon Barkhuizen
Simon Barkhuizen

Reputation: 846

Change NSASCIIStringEncoding to NSUTF8StringEncoding .

I ran a quick test now with some dummy data and seemed to work fine with just that one line.

Upvotes: 1

unexpectedvalue
unexpectedvalue

Reputation: 6139

NSData *utf8Data = [txt dataUsingEncoding:NSUTF8StringEncoding];

Upvotes: 5

Related Questions