【问题标题】:Unexpected output when transforming char which is larger than 127 to NSString将大于 127 的 char 转换为 NSString 时出现意外输出
【发布时间】:2012-03-09 04:14:02
【问题描述】:
    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'应该作为一个单字节数据发送。

【问题讨论】:

  • 从最后一行开始,听起来您只是在发送数据,而不是真正假设要表示文本(即:unichar)。那么,呃,为什么要创建一个 NSString 而不是一个 NSData?!

标签: objective-c nsstring char


【解决方案1】:

使用此功能:

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

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

unichar temp[] = {233};  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    相关资源
    最近更新 更多