问题描述
我正在尝试在文本字符串中插入unicode连字符。我看到无效的通用字符错误,包含以下内容:
I am trying to insert a unicode hyphen-minus character into a text string. I am seeing an "Invalid universal character" error with the following:
u + 002D(连字符 - 减号)
u+002D (hyphen-minus)
[textViewContent insertString:@"\u002D" atIndex:cursorPosition.location];
但是,这些工作正常:
u + 2212(减号)
u+2212 (minus)
[textViewContent insertString:@"\u2212" atIndex:cursorPosition.location];
u + 2010(连字符)
u+2010 (hyphen)
[textViewContent insertString:@"\u2010" atIndex:cursorPosition.location];
我在这里讨论了几个现有的Unicode讨论,但我没有找到解释我的例子中有什么不同导致第一个错误。洞察力非常感谢。
I've poked at several of the existing Unicode discussions here, but I have not found one that explains what is different amongst my examples that causes the first one to error. Insight greatly appreciated.
推荐答案
Unversal角色名称对其使用有一些限制。在C99和C ++ 98中,您不允许使用引用基本字符集中字符的字符集(包括U + 002D)。
Unversal character names have some restrictions on their use. In C99 and C++98 you were not allowed to use one that referred to a character in the basic character set (which includes U+002D).
C ++ 11已更新此要求,因此如果您在字符串或字符文字内,则可以使用引用基本字符的UCN。根据您使用的编译器版本,我猜您可以使用Objective-C ++ 11来使您的代码合法。
C++11 has updated this requirement so if you are inside a string or character literal then you are allowed to use a UCN that refers to basic characters. Depending on the compiler version you're using I would guess that you could use Objective-C++11 to make your code legal.
这就是说,因为这个字符是ASCII和基本字符集的一部分,你为什么不按字面意思写它?
That said, since this character is part of ASCII and the basic character set, why don't you just write it literally?
@"-"
这篇关于将Unicode Hyphen-minus插入到String中会导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!