Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kraitz

macrumors newbie
Original poster
Nov 22, 2011
1
0
Hi,

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

NSDATA : 4c000230 30303037 34323030

i convert with this statement:
Code:
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?
 
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?
 
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?

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.)
 
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.