How to convert NSMutableData to NSString on iPhone?

Chilly Zhong picture Chilly Zhong · Feb 27, 2009 · Viewed 34.2k times · Source

I received an NSMutableData from a server and now I want to convert it to an NSString. Any ideas about how to do this?

Answer

codelogic picture codelogic · Feb 27, 2009

You can use the initWithData: initializer:

[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

Change the encoding to that of the source data.