Avatar
norio_nomura 1/31/2019 1:51 AM
Swift 4までのUTF8View.IndexUnicodeScalarの境界に合わせられていました。 @swift-4.2.4 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 utf8Index = family.utf8.index(before: family.utf8.endIndex) let utf8Before = String(family[..<utf8Index]) printUnicodeScalars(utf8Before) let utf8After = String(family[utf8Index...]) printUnicodeScalars(utf8After) printUnicodeScalars(utf8Before + utf8After) print(utf8After.utf8.count)