EmEditorで文字数をカウントするマクロ (JavaScript版) を作成した
EmEditorで文字数をカウントしたかったので、「emeditor 文字数」で検索して、「EmEditor私のマクロその1 文字数カウント - PowerShell Scripting Weblog」を参考にして適当に作ってみた。
<変えた点>
- ソースがVBだったのでJavaScriptに
- 範囲選択されていなかった時は対象を文章全体に
- Alertに文字数だけでなく簡単な説明を表示(「文字数(文書全体):」「文字数(選択範囲):」)
strTitle = "文字数"; strLength = 0; if (document.selection.Text == "") { strTitle += "(文書全体)"; strLength = getAllLengthOfText(); } else { strTitle += "(選択範囲)"; strLength = document.selection.text.length; } alert ( strTitle + ":" + strLength ); function getAllLengthOfText() { lngLines = document.GetLines(); rtn = 0; for (i = 1; i <= lngLines; i++) { str = document.GetLine( i ); rtn += str.length; } return rtn; }