如何将 NSString 转换为字符?



我知道这之前已经回答过了,但那是大约 7 年前的事了,似乎不再相关了。

我目前正在做什么(不起作用,现在似乎无关紧要(

NSString sPath = [path string];
#define BUFSIZ 256
char cPath[BUFSIZ];
[sPath getCString:cPath maxlength:BUFSIZ encoding:NSUTF8Encoding];

我得到的错误:

error: use of undeclared identifier 'NSUTF8Encoding'
error: instance method '-getCString:maxlength:encoding:' not found (return type defaults to 'id') [-Werror,-Wobjc-method-access]

谢谢!

>NSUTF8Encoding不存在。以下是NSString编码的列表:

https://developer.apple.com/documentation/foundation/nsstringencoding?language=objc

你可能想要NSUTF8StringEncoding.所有的基础类及其参数都在线记录在Xcode中,包括getCString:maxLength:encoding

Objective-c也是一种区分大小写的语言。方法、对象和变量都需要正确的拼写,包括正确的大小写。

最新更新