01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
2010-01-20 Wed
■ UTF-8 の文字数を求める [D言語]
以下のコードで求まる
import std.stdio; import std.utf; void main() { string s = "あいうえお"; //UTF-8 な文字列 size_t count = toUCSindex(s,s.length); writeln(count); //文字数は 5 }
逆に任意の文字位置からバイト位置を求めるには以下のコード。
import std.stdio; import std.utf; void main() { string s = "あいうえお"; //UTF-8 な文字列 size_t index = toUTFindex(s,3);//3文字目の位置 writeln(index); }