Last active
May 22, 2021 16:34
-
-
Save krzyzanowskim/732cfb2acf8fbb630d06a981856d5b8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let str = "abc😂" | |
str.count // 4 | |
str.utf16.count // 5 | |
str.utf8.count // 7 | |
import Foundation | |
(str as NSString).length // 5 | |
(str as NSString).lengthOfBytes(using: String.Encoding.utf8.rawValue) // 7 | |
(str as NSString).lengthOfBytes(using: String.Encoding.unicode.rawValue) // 10 | |
(str as NSString).lengthOfBytes(using: String.Encoding.unicode.rawValue) // 10 | |
(str as NSString).lengthOfBytes(using: String.Encoding.utf32.rawValue) // 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment