OGeek|极客世界-中国程序员成长平台

标题: objective-c - char 数组到 [NSString stringWithFormat :] [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:04
标题: objective-c - char 数组到 [NSString stringWithFormat :]

我的代码中有这段代码(md5 散列)

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]
              ];

有没有比这段代码更快的方法,如何在 NSString 中推送整个数组?



Best Answer-推荐答案


这是将 16 个字符十六进制转换为 NSString 的最快方法。如果您经常这样做,请将其包装在一个函数中,这样您就只有一份代码副本。

关于objective-c - char 数组到 [NSString stringWithFormat :],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7283469/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4