2010-01-20
以下のコードで求まる
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); }