Search code examples
nsstringasciinsdatansstringencoding

NSData to NSString losing data


I'm attempting to convert a binary file into text, the problem is that a large portion of the file was not encoded in ascii and ends up being special characters. I'm using

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

but am only getting a few characters back in a 20000 byte data block. What I would like to be able to see is all of the text (even if most is nonsense), which is what I get when I open the file using a binary editor.

enter image description here


Solution

  • It's a binary file. To read it, you find the documentation for the file format, then you parse it. Trying to throw it all into an NSString* seems absolutely pointless.