在Objective-C中转换或转换char到NSString [英] Casting or converting a char to an NSString in Objective-C

查看:150
本文介绍了在Objective-C中转换或转换char到NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一个字符转换为NSString在Objective-C?



不是一个以null结尾的C字符串,只是一个简单的可以使用 stringWithFormat:

/ code>,以%c 的格式传递以表示一个字符,如下所示:

  char c ='a'; 
NSString * s = [NSString stringWithFormat:@%c,c];


How do I convert a char to an NSString in Objective-C?

Not a null-terminated C string, just a simple char c = 'a'.

解决方案

You can use stringWithFormat:, passing in a format of %c to represent a character, like this:

char c = 'a';
NSString *s = [NSString stringWithFormat:@"%c", c];

这篇关于在Objective-C中转换或转换char到NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆