環境によって、絵文字の絵柄がちがうことがわかる。
iPhone から猫の絵文字「🐱」を Twitter に投稿してみた。
投稿先 ⇒ NI-Lab.さんはTwitterを使っています: "🐱ねこ"
iPhone + iOS + Safari で Twitter のサイトを見る。
Nexus 7 + Android + Chrome で Twitter のサイトを見る。
MacBook Air + Mac OS X + Firefox で Twitter のサイトを見る。
Twitter から猫の絵文字「🐱」のデータを取り込んでみた。
取り込み先 ⇒ nilog: 🐱ねこ (2015-02-28)
MacBook Air + Mac OS X + Chrome で見る。
Nexus 7 + Android + Chrome で見る。
VAIO Tap 20 + Windows 8.1 + Firefox で見る。
Java のプログラムで猫の絵文字「🐱」の中身を調べる
サンプルコード。
public class NekoEmoji {
public static void main(String[] args) {
nekoTest("猫"); // 猫の漢字
nekoTest("🐱"); // 猫の絵文字
}
private static void nekoTest(String neko){
// 対象文字
System.out.println(neko);
// 文字列の長さ?
System.out.println("length: " + neko.length());
// 文字列を構成する char を出力
System.out.print("String to chars: ");
for(int i=0; i<neko.length(); i++){
System.out.print((int)neko.charAt(i) + ", ");
}
System.out.println();
// Unicode コードポイント
int codePoint = neko.codePointAt(0);
System.out.println("code point: " + codePoint);
// Unicode コードポイントから char を求める
char[] chars = Character.toChars(codePoint);
System.out.print("Code point to chars: ");
for(char c : chars){
System.out.print((int)c + ", ");
}
System.out.println();
}
}
実行結果。
猫
length: 1
String to chars: 29483,
code point: 29483
Code point to chars: 29483,
🐱
length: 2
String to chars: 55357, 56369,
code point: 128049
Code point to chars: 55357, 56369,
-
ref.
- [ヅ] MySQL + Java で UTF-8 の4バイト文字に対応 (utf8mb4) (2015-02-28)
- [ヅ] 「𩸽」(ほっけ) という文字はUTF-8で4バイトになる (2015-02-26)
tags: unicode java
Posted by NI-Lab. (@nilab)