本文介绍了将十六进制字符串转换为long的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有任何Cocoa类可以帮助我将NSString中的十六进制值转换为 0x12FA
到 long
或 NSNumber
?它看起来不像任何类如 NSNumberFormatter
支持十六进制数字。
Are there any Cocoa classes that will help me convert a hex value in a NSString like 0x12FA
to a long
or NSNumber
? It doesn't look like any of the classes like NSNumberFormatter
support hex numbers.
谢谢,
Hua-Ying
Thanks,Hua-Ying
推荐答案
这里有一个简短的例子说明如何使用NSScanner:
Here's a short example of how you would do it using NSScanner:
NSString* pString = @"0xDEADBABE";
NSScanner* pScanner = [NSScanner scannerWithString: pString];
unsigned int iValue;
[pScanner scanHexInt: &iValue];
这篇关于将十六进制字符串转换为long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!