将大于127的char转换为NSString时出现意外输出

时间:2012-03-09 04:14:02

标签: objective-c nsstring char

    unichar temp=233;
    return [NSString stringWithFormat:@"%c",temp];

    //Type of 'temp" changed from unichar to char do not affects the output no matter it's char or unichar

输出: NSString:0xc388,不是预期的0xE9
       长度:1

我们需要将一堆数据作为数据包发送,“233”应作为单字节数据发送。

1 个答案:

答案 0 :(得分:0)

使用此功能:

+ (id)stringWithCharacters:(const unichar *)chars length:(NSUInteger)length

因为输入是一个数组,所以从这开始:

unichar temp[] = {233};