Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
2017.04.11 MySQL勉強会 in 大阪 第10回 https://atnd.org/events/86982 で文字情報を示すために使ったコード
//: Playground - noun: a place where people can play
import UIKit
// see http://stackoverflow.com/a/40089462/518639
extension Data {
func hexEncodedString() -> String {
return map { String(format: "%02hhx", $0) }.joined()
}
}
// UTF16 BE hex を得る
extension String {
func hex() -> String {
return (self.data(using: String.Encoding.utf16BigEndian, allowLossyConversion: false))!.hexEncodedString()
}
}
"0".hex() // ASCII 0x30 / U+0030
" ".hex() // U+3000 全角スペース
"👩".hex()
"👩🏻".hex()
"👩🏼".hex()
"👩🏽".hex()
"👩🏾".hex()
"👩🏿".hex()
// modifiers http://www.fileformat.info/info/charset/UTF-16/list.htm?start=55670
"👩".hex() // U+1F469
"👩🏻".hex() // U+1F469 + U+1F3Fb
"𤭢".hex() // 何か中国語の漢字 U+24B62 https://en.wiktionary.org/wiki/%F0%A4%AD%A2
// これらはどのようにソートされるのが好都合なのでしょうか?
"👩".hex()
"👩a".hex()
"👩🏻".hex() // U+1F469 + U+1F3Fb
"👩𤭢".hex()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.