格式指定类型为"unsigned short",但参数的类型为"int" [英] Format specifies type 'unsigned short' but the argument has type 'int'

查看:283
本文介绍了格式指定类型为"unsigned short",但参数的类型为"int"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个扫描字符串的方法,将任何新行转换为HTML的<br>.有问题的行是:

I have a method that scans a string, converting any new lines to <br> for HTML. The line in question is:

NSCharacterSet *newLineCharacters = [NSCharacterSet characterSetWithCharactersInString:
          [NSString stringWithFormat:@"\n\r%C%C%C%C", 0x0085, 0x000C, 0x2028, 0x2029]];

Xcode在这里给我一个警告:

Xcode gives me a warning here:

Format specifies type 'unsigned short' but the argument has type 'int'

建议将所有%C都更改为%d,但是事实证明该功能无效.正确的方法是什么?为什么Xcode建议使用错误的方法?

It's recommending that I change all %C to %d, however that turns out to break the function. What is the correct way to do this, and why is Xcode recommending the wrong thing?

推荐答案

一种选择是将您的参数强制转换为无符号缩写:即(unsigned short)0x0085

One option is to cast your arguments to unsigned short: i.e. (unsigned short)0x0085 etc

但是,如果您要查找换行符,则应仅使用换行符字符集.这是符合Unicode的代码":[ NSCharacterSet newlineCharacterSet ]

But if you're looking for newlines, you should just use the newline character set. This is "Unicode compliant":[ NSCharacterSet newlineCharacterSet ]

修改

重新讨论此问题:如果尝试通过换行符分隔NSString/CFString,则可能应使用-[ NSString getLineStart:end:contentsEnd:forRange:].

Revisiting this question: If you are trying to separate an NSString/CFString by line breaks, you should probably use -[ NSString getLineStart:end:contentsEnd:forRange:].

这篇关于格式指定类型为"unsigned short",但参数的类型为"int"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆