Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Last active May 22, 2021 16:34
Show Gist options
  • Save krzyzanowskim/732cfb2acf8fbb630d06a981856d5b8e to your computer and use it in GitHub Desktop.
Save krzyzanowskim/732cfb2acf8fbb630d06a981856d5b8e to your computer and use it in GitHub Desktop.
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