characterAtIndex转换为NSString

时间:2013-02-08 00:44:42

标签: cocoa nsstring

我在此代码的最后一行收到错误消息Incompatible integer to pointer conversion sending 'unichar' (aka 'unsigned short') to parameter of type 'NSString *'

NSMutableString *sp = [[NSMutableString alloc] initWithString:@"             "];
NSArray *deals=@[@[sp, sp, sp, sp], @[sp, sp, sp, sp]];
NSString* suits = @"NESW";
[deals[0][3] replaceCharactersInRange:NSMakeRange(1, 1) withString:[suits characterAtIndex:2]];

1 个答案:

答案 0 :(得分:2)

如错误所示,characterAtIndex:返回unichar而replaceCharactersInRange:withString:需要NSString。如果您想要一个索引为2的NSString,请尝试使用substringWithRange:NSMakeRange(2,1)