Gre*_*reg 4 iphone int objective-c char ios
我有一个应用程序设置,我将NSString转换为char变量数组,我试图将一些字符转换为整数(基本上解析字符串中的数字).但是当我尝试将它们转换为int变量时,它们会突然改变值.
例如:
char thechar = array[7]; //to make sure the issue isn't related to the array
NSLog(@"%c %i %i",thechar,(int) thechar, [[NSNumber numberWithUnsignedChar:thechar] intValue]);
Run Code Online (Sandbox Code Playgroud)
返回:
3 51 51
Run Code Online (Sandbox Code Playgroud)
转换它的两种方法(我发现)似乎都将值更改为51.有谁知道可能会发生什么?
Gre*_*reg 11
我想通了:只需将其转换为NSString,然后获取intValue.
[[NSString stringWithFormat:@"%c", thechar] intValue];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4704 次 |
| 最近记录: |