0

Suppose I am trying to print out a string like this:

NSLog(@"*** DOWNLOAD START ***\n%@\n*** DOWNLOAD END ***", bufString);

bufString is an NSString. What could bufString contain to cause the output to get truncated after its first character? My guess is that it has something to do with newline representation being translated to a string termination character.

The complete readout from the log of this statement:

2012-08-02 12:20:02.595 MyApp[18863:710f] *** DOWNLOAD START ***
{

The result of [bufString length] is 15914. The data it is trying to display is a multi-line JSON.

What might I do to print out the entire string?

Ben Flynn
  • 18,524
  • 20
  • 97
  • 142
  • Have you looked at the next line? –  Aug 02 '12 at 19:28
  • Look at this question; you might be able to get a solution out of it. http://stackoverflow.com/q/3581532/1487063 – Dustin Aug 02 '12 at 19:38
  • 1
    You can investigate the contents by converting `NSString` to C string (may be harmless to convert to ASCII), go over it in a loop and print code of each byte. You'll see if there are any strange control-char values. – coverback Aug 02 '12 at 19:38
  • Hmm it appears that every 4th character is actually a character when I iterate through... – Ben Flynn Aug 02 '12 at 19:54
  • I think I'm creating the NSString from something that looks like it should be an array of character bytes but in fact three out of every four char width elements is zero. This is probably the result of someone doing some tricks with the array initialization (out of my control). I'll probably close this question since it's pretty specific to my environment I think. – Ben Flynn Aug 02 '12 at 20:16

1 Answers1

0

In my case I created the NSString from bytes, but only every fourth byte contained character information. Bottom line -- if you create an NSString from bytes make sure you know what's in that memory! Iterating through the NSString character at a time and printing the result (suggested by coverback) revealed the issue.

Ben Flynn
  • 18,524
  • 20
  • 97
  • 142