如何将char数组的一部分转换为NSString *?

时间:2012-03-06 05:46:10

标签: ios nsstring cstring

char arr[] = "abcdefg";
// I know I can do this
NSString *s = [[NSString alloc] initWithCString:arr encoding:NSUTF8StringEncoding];

如果我想将部分arr数组转换为NSString *?说cde而不是整个字符串abcdefg?我如何实现这一目标?

1 个答案:

答案 0 :(得分:4)

NSString *s = [[NSString alloc] initWithBytes:arr + 2
    length:3 encoding:NSUTF8StringEncoding];