実は、これはJavaScriptの標準機能に含まれてますので、難しくありません。
jsmode "WebView2\\" + currentmacrofilename; js { debuginfo(2); function main() { let totalText = gettotaltext(); // セグメンター 'ja' は言語タグ、'grapheme' はテキスト要素(字)を分割する単位 const segmenter = new Intl.Segmenter('ja', { granularity: 'grapheme' }); // ここに格納する。 let charArray = [] // グラフェムイテレータ function* graphemeIterator(text) { for (const segment of segmenter.segment(text)) { yield segment.segment; // 各segmentのsegmentプロパティには字が含まれる } } for (const grapheme of graphemeIterator(totalText)) { charArray.push(grapheme); } console.log(JSON.stringify(charArray)); } hidemaru.setTimeout(main, 0); }
WebView2の実行空間の変数は十分大きいメモリ制限ですので
jsmode "WebView2\\" + currentmacrofilename; js { let text = "ぁ゙いうえおかヴゔ"; let segmenter = new Intl.Segmenter("ja", { granularity: "grapheme" }); let charArray = [...segmenter.segment(aaa)].map(s => s.segment); debuginfo(2); console.log(JSON.stringify(charArray)); }
みたいな形でも、30メガとかのテキストでない限りは問題はありません。