char arr[] = "abcdefg";
// I know I can do this
NSString *s = [[NSString alloc] initWithCString:arr encoding:NSUTF8StringEncoding];
如果我想将部分arr
数组转换为NSString *?说cde
而不是整个字符串abcdefg
?我如何实现这一目标?
答案 0 :(得分:4)
NSString *s = [[NSString alloc] initWithBytes:arr + 2
length:3 encoding:NSUTF8StringEncoding];