Automated Way of Displaying a Hex Dump of a Binary File in a UITextView
- Add a new view controller that displays the contents of the file in a UITextView. If the file is binary, display a hexadecimal readout. When the user taps on a file, a new view controller should be pushed onto the navigation controller's stack that displays the contents of the file. The new view controller should have a Back button.
There were other requests on in this "Further Study" section and I have this example worked through, all except for how to display a hex dump of the file. ie:
0000: 31 32 33 34 35 36 37 38 12345678
.....
Right now, I have the program set to read the file into an NSString and load it into the UITextView. This works fine for text files, but it doesn't work well for binary files. I'm currently using the following code to load the file:
UITextView *textView = [[UITextView alloc] initWithFrame:bounds];
textView.editable = NO;
NSString *string = [NSString stringWithContentsOfFile:currentFile encoding:NSASCIIStringEncoding error:NULL];
textView.text = string;
Looking at UITextView.h and the UITextView Class Reference, I don't see anything that looks like it has this functionality built-in. Just curious if I'm missing some built-in way to accomplish this (maybe it's somewhere else in the API). I wanted to see if there was an easy way to do this before I brushed off my programming skills and implement this by coding it from scratch.
As far as needing to implement this from scratch, I'm guessing this could be done "relatively" easily by using various NSString methods to reformat the binary data into a hex dump format.
Steve
Message was edited by: Steve Waltner
MacBook Pro, iMac G5, Mac OS X (10.5)