「新規行番号入力」の版間の差分
ナビゲーションに移動
検索に移動
変数の宣言を分割 |
ソースコードを整形 |
||
| 8行目: | 8行目: | ||
=== ソースコード === | === ソースコード === | ||
<syntaxhighlight lang="javascript" copy> | <syntaxhighlight lang="javascript" copy> | ||
//全消去 | // 全消去 | ||
document.selection.SelectAll(); | document.selection.SelectAll(); | ||
document.selection.DeleteLeft(1); | document.selection.DeleteLeft(1); | ||
var r = new RegExp(prompt("整数2桁までを入力してください", "")); | var r = new RegExp(prompt("整数2桁までを入力してください", "")); | ||
//値の取得 | // 値の取得 | ||
document.selection.Text = r; | document.selection.Text = r; | ||
document.selection.Replace("/", "", meFindNext | meReplaceAll); | document.selection.Replace("/", "", meFindNext | meReplaceAll); | ||
| 22行目: | 22行目: | ||
let x = 0; | let x = 0; | ||
for (let step = 0; step < j; step++) { | for (let step = 0; step < j; step++) { | ||
// 値が 0 から jまで実行される | |||
x = step + 1; | |||
document.selection.Text = x; | document.selection.Text = x; | ||
document.selection.Text = "."; | document.selection.Text = "."; | ||
| 39行目: | 39行目: | ||
<syntaxhighlight lang="javascript" copy> | <syntaxhighlight lang="javascript" copy> | ||
var r = Prompt("整数を入力してください", "") | var r = Prompt("整数を入力してください", "") | ||
.replace(/[0-9]/g, function(tmp) { | |||
return String.fromCharCode(tmp.charCodeAt(0) - 0xFEE0); | |||
}).replace(/\D/g, ""); | |||
if (r) { | if (r) { | ||
var r1 = ""; | |||
var r2 = ""; | |||
var str = ""; | |||
// r1 = Prompt("数字の前に追加したい文字列を入力してください", ""); | |||
r2 = Prompt("数字の後ろに追加したい文字列を入力してください", ""); | |||
for (var i = 1; i <= +r; i++) { | |||
str += r1 + i + r2 + "\n"; | |||
} | |||
Document.Text = str.replace(/\n$/, ""); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
2026年9月10日 (木) 00:02時点における版
このマクロはMery Ver 3.6.1で追加されたサンプルマクロの「番号の挿入」と同機能です。
2桁以下まで可
1. 2. といった行番号を入れるだけのマクロです。99.まで可能です。
※最初に使用してください。一度すべてを消去してから入力します。
ソースコード
// 全消去
document.selection.SelectAll();
document.selection.DeleteLeft(1);
var r = new RegExp(prompt("整数2桁までを入力してください", ""));
// 値の取得
document.selection.Text = r;
document.selection.Replace("/", "", meFindNext | meReplaceAll);
var h = new RegExp("[0-9][0-9]");
let j = h.exec(r)[0];
document.selection.Replace("[0-9]", "", meFindNext | meFindAround | meFindReplaceRegExp | meReplaceAll);
let x = 0;
for (let step = 0; step < j; step++) {
// 値が 0 から jまで実行される
x = step + 1;
document.selection.Text = x;
document.selection.Text = ".";
document.selection.NewLine(1);
}
3桁以上も可
- UNDO 1回で元に戻る。
- 3桁以上も指定可。
- 数字の前後に付加する文字列の指定可。
- デフォルトでは後ろに付加する文字列の指定のみ。
ソースコード
var r = Prompt("整数を入力してください", "")
.replace(/[0-9]/g, function(tmp) {
return String.fromCharCode(tmp.charCodeAt(0) - 0xFEE0);
}).replace(/\D/g, "");
if (r) {
var r1 = "";
var r2 = "";
var str = "";
// r1 = Prompt("数字の前に追加したい文字列を入力してください", "");
r2 = Prompt("数字の後ろに追加したい文字列を入力してください", "");
for (var i = 1; i <= +r; i++) {
str += r1 + i + r2 + "\n";
}
Document.Text = str.replace(/\n$/, "");
}
スポンサーリンク