converting data back into a string

objectiveccoder001 picture objectiveccoder001 · Aug 9, 2010 · Viewed 37k times · Source

So I have this:

  NSData *charlieSendData = [[charlieImputText stringValue] dataUsingEncoding:NSUTF8StringEncoding];

I know how to convert NSStrings to data but how I convert data back to an NSString?

Elijah

Answer

Jacob Relkin picture Jacob Relkin · Aug 9, 2010

You can use NSString's -initWithData:encoding: initializer method.

NSData *charlieSendData = [[charlieImputText stringValue] dataUsingEncoding:NSUTF8StringEncoding]
NSString *charlieSendString = [[NSString alloc] initWithData:charlieSendData encoding:NSUTF8StringEncoding];