Discussion in 'iOS Programming' started by kraitz, Nov 22, 2011.

  1. kraitz macrumors newbie

    Nov 22, 2011

    I'm trying to convert a NSDATA string consisting of hex to NSString.

    NSDATA : 4c000230 30303037 34323030

    i convert with this statement:
    NSString *msg =  [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease]; 
    but when i print msg, it only converts the first character. which is L. i realized that it always terminates at NULL (00) and the rest will be blank. How do i convert the while thing?
  2. admanimal macrumors 68040

    Apr 22, 2005
    So you are saying that your NSData object contains some data, and you want the hex representation of the bytes in that data as an NSString?
  3. ArtOfWarfare macrumors G3


    Nov 26, 2007
    No, I believe he said the first character was "L", so he wants the actual text from the data, not the hex. (I can help clarify the question, I don't know the answer. I would suspect googling would turn up some answers from Stack Overflow.)
  4. chown33 macrumors 604

    Aug 9, 2009
    on the Western Slopes, with E. A. Poe
    Post the code that prints the NSString.

    You're converting from an NSData object, so why not use initWithData:encoding:?

    After conversion to NSString, exactly what is the string's length?

Share This Page