如何将ASCII值转换为Objective-C中的字符? [英] How to convert ASCII value to a character in Objective-C?
本文介绍了如何将ASCII值转换为Objective-C中的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有人在Objective-C中为iPhone开发提供以下PHP功能等价物:
I was wondering if anyone has the following php function equivalents in Objective-C for iPhone development:
- ord()#返回字符串第一个字符的ASCII值。
- chr()#返回指定ASCII值的字符。
非常感谢!
推荐答案
这是使用ASCII值和的NSString
。请注意,由于 NSString
正在使用unichars,因此非ASCII字符串可能会出现意外结果。
This is how you can work with ASCII values and NSString
. Note that since NSString
is working with unichars, there could be unexpected results for a non ASCII string.
// NSString to ASCII
NSString *string = @"A";
int asciiCode = [string characterAtIndex:0]; // 65
// ASCII to NSString
int asciiCode = 65;
NSString *string = [NSString stringWithFormat:@"%c", asciiCode]; // A
这篇关于如何将ASCII值转换为Objective-C中的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文