View Full Version : Getting a NSString from NSMutableData, possible?
Monkaaay
Jul 16, 2006, 08: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, 09: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 17, 2006, 12:57 AM
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, 07: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.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.