Avatar
@swift-4.2.4 @swift-5.0.3 func printUnicodeScalars<S: StringProtocol>(_ string: S) { print(string.unicodeScalars.map { "\\u{\(String($0.value, radix: 16))}" }.joined()) } // https://emojipedia.org/family-man-woman-girl-boy/ let family = "\u{1f468}\u{200d}\u{1f469}\u{200d}\u{1f467}\u{200d}\u{1f466}" printUnicodeScalars(family) let utf16Index = family.utf16.index(before: family.utf16.endIndex) let utf16Before = String(family[..<utf16Index]) printUnicodeScalars(utf16Before) let utf16After = String(family[utf16Index...]) printUnicodeScalars(utf16After) printUnicodeScalars(utf16Before + utf16After) print(utf16After.utf16.count) (edited)