Marek Sebera
Marek Sebera

Reputation: 40631

char array to [NSString stringWithFormat:]

I have this code in my code (md5 hashing)

unsigned char result[16];
// fill result with data
[NSString stringWithFormat: 
              @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
              result[0], result[1], result[2], result[3], 
              result[4], result[5], result[6], result[7],
              result[8], result[9], result[10], result[11],
              result[12], result[13], result[14], result[15]
              ];

Is there some faster way, how to push whole array in NSString than this code?

Upvotes: 2

Views: 885

Answers (1)

Jonathan Grynspan
Jonathan Grynspan

Reputation: 43472

That's the fastest way to hexify 16 characters into an NSString. If you do this often, wrap it up in a function so you only have one copy of the code. :)

Upvotes: 3

Related Questions