1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Getting a NSString from NSMutableData, possible?

Discussion in 'Mac Programming' started by Monkaaay, Jul 16, 2006.

  1. macrumors 6502

    Monkaaay

    #1
    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?
     
  2. macrumors 6502

    Monkaaay

    #2
    Well, I found this solution but I wish it were more elegant.

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

    HiRez

    #3
    How about

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


    Not sure if that's really any better though.
     
  4. macrumors 68000

    GeeYouEye

    #4
    Or just use stringWithContentsOfURL:encoding: (I think that's the method...)
    Also, NSLog(s) would work as well.
     

Share This Page