与其他一些表情符号字符一样,0x0001F1E9 0x0001F1EA组合(德国标志)在屏幕上表示为单个字符,尽管它实际上是两个不同的Unicode字符点组合在一起.它在Swift中表示为一个或两个不同的字符吗?
let flag = "\u{1f1e9}\u{1f1ea}"
然后flag
是.
有关更多区域指标符号,请参阅:http:
//en.wikipedia.org/wiki/Regional_Indicator_Symbol
Swift 3在其String
结构中实现了Unicode .在Unicode中,所有标志都是区域指示符号对.所以, is actually
接着是
(try copying the two and pasting them next to eachother!).
When two or more Regional Indicator Symbols are placed next to eachother, they form an "Extended Grapheme Cluster", which means they're treated as one character. This is why " = ...".characters
给你["", " ", "=", " ", "", ".", ".", "."]
.
如果你想看到每一个Unicode代码点(AKA"标量"),你可以使用.unicodeScalars
,这样就可以"Hi!".unicodeScalars
了["H", "i", "", "", "!"]
是一个字符(在Swift和Unicode中),由两个代码点(AKA标量)组成.不要忘记这些是不同的!
为什么像????这样的表情符号字符在Swift字符串中处理得如此奇怪?
Swift编程语言(Swift 3.1) - 字符串和字符 - Unicode
与此同时,Swift也增加了对"扩展字形集群"的支持.迭代字符串的字符会为"flags"生成一个字符:
let string = "Hi!" for char in string.characters { print(char) }
输出:
H i !