String.UTF16View
Overview
You can access a string’s view of UTF-16 code units by using its utf16 property. A string’s UTF-16 view encodes the string’s Unicode scalar values as 16-bit integers.
Unicode scalar values that make up a string’s contents can be up to 21 bits long. The longer scalar values may need two UInt16 values for storage. Those “pairs” of code units are called surrogate pairs.
To convert a String.UTF16View instance back into a string, use the String type’s init(_:) initializer.
UTF16View Elements Match NSString Characters
The UTF-16 code units of a string’s utf16 view match the elements accessed through indexed NSString APIs.
Unlike NSString, however, String.UTF16View does not use integer indices. If you need to access a specific position in a UTF-16 view, use Swift’s index manipulation methods. The following example accesses the fourth code unit in both the flowers and nsflowers strings:
Although the Swift overlay updates many Objective-C methods to return native Swift indices and index ranges, some still return instances of NSRange. To convert an NSRange instance to a range of String.Index, use the Range(_:in:) initializer, which takes an NSRange and a string as arguments.
原文链接: String.UTF16View https://www.huajiangbk.com/newsview1293850.html
| 上一篇: 陈星汉作品:《Flower花》与... | 下一篇: 微信小程序第一天 文件上传实现 |
推荐分享

- 1胡椒木盆景从上盆制作到养护,... 74348
- 2明日花キララ:明日花绮罗年度... 53865
- 3明日花キララ(明日花绮罗)经... 31164
- 4五月天婷婷开心六月丁香:音乐... 20427
- 5仙人球“水蜜桃”—又美又仙,... 18095
- 6兰花叶子扭的是什么兰 17471
- 7十大致癌花卉排行榜,哪些花卉... 16661
- 8超简单,3个步骤带你学会毛线... 16116
- 9老师精选05—河北彩花(出道... 15560
- 10李晓明工笔牡丹(魏紫)《牡丹... 14958




