PDA

View Full Version : Getting a NSString from NSMutableData, possible?




Monkaaay
Jul 16, 2006, 07:51 PM
I'm trying to read the contents of a URL and I came across the NSURLRequest and NSURLConnection objects. I have a NSMutableData object filled with the results but I can't find a way to print that data to the screen. Any ideas?



Monkaaay
Jul 16, 2006, 08:11 PM
Well, I found this solution but I wish it were more elegant.


unsigned char byteBuffer[[receivedData length]];
[receivedData getBytes:byteBuffer];
NSLog(@"Output: %s", (char *)byteBuffer);

HiRez
Jul 16, 2006, 11:57 PM
How about

NSString *s = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
NSLog(@"%@", s);
[s release];

Not sure if that's really any better though.

GeeYouEye
Jul 17, 2006, 06:27 PM
How about

NSString *s = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
NSLog(@"%@", s);
[s release];

Not sure if that's really any better though.
Or just use stringWithContentsOfURL:encoding: (I think that's the method...)
Also, NSLog(s) would work as well.