NSString get -characters

岁酱吖の 提交于 2019-12-17 16:29:59

问题


I want to get the characters of an NSString. Like this:

NSString *data;
const char * typein = [[data characters] UTF8String];

But obviously NSString won't respond to -characters. How do I get the characters of NSString?

thanks, Elijah


回答1:


You can use this function:

for(int i =0 ;i<[myString length]; i++) {
  char character = [myString characterAtIndex:i];
}

or

NSString *str = @"astring";
const char *cString = [str UTF8String];



回答2:


If you just want to get a cString from the NSString just call UTF8String as you are already doing and then iterate the array.



来源:https://stackoverflow.com/questions/3886882/nsstring-get-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!