我需要将一个字符传递到第 1 行。 2:我尝试的第一种方法,
1) unichar dicttxt = [[myword lowercaseString] characterAtIndex:0];
2) fileName = [[NSBundle mainBundle] pathForResource:dicttxt ofType: @"txt"];
我尝试过的第二种方法,
NSString *dicttxt = [[myword lowercaseString] characterAtIndex:0];
fileName = [[NSBundle mainBundle] pathForResource:dicttxt ofType: @"txt"];
两种方法都提示错误从整数创建指针而不进行强制转换。
最佳答案
不要使用字符,而是使用:
NSString *dicttxt = [[myword lowercaseString] substringWithRange:NSMakeRange(0, 1)];
fileName = [[NSBundle mainBundle] pathForResource:dicttxt ofType:@"txt"];
或者(我完全忘记了这个方法),以下内容在功能上与上面相同,但更简洁:
NSString *dicttxt = [[myword lowercaseString] substringToIndex:1];
fileName = [[NSBundle mainBundle] pathForResource:dicttxt ofType:@"txt"];
这些将起作用,只要:
myword
的长度至少为 1。myword
不以复合字符开头(即“café”可以,但“über”可能不行)。
关于iphone - 如何传递unichar对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3572315/