How to convert NSData to NSString?

1

I have a variable nsdata that is a byte array, and I want it as a string, but I do not want to decode it, I just want to have the same frame but in string.

nsdata = <024101e6 90eaf082 01e0df42 020002df 3d106967 e83efea5 c7bfe062 dca4737b 101bdf16 088c9877>

and I want to have it exactly the same but as a string:

nsstring = "<024101e6 90eaf082 01e0df42 020002df 3d106967 e83efea5 c7bfe062 dca4737b 101bdf16 088c9877>";

How could I do it?

    
asked by Sergio Aldo Mejía Rodríguez 14.12.2016 в 18:26
source

2 answers

0

Assuming that nsdata is of type NSData * , you can use:

NSString *str = [nsdata description];
    
answered by 14.12.2016 / 18:36
source
0

This would be the way, defining an encoding using NSString :

NSString *miString = [[[NSString alloc] initWithData:data
                                         encoding:NSUTF8StringEncoding] autorelease];
    
answered by 14.12.2016 в 18:36