1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

選択した文字列をコメントアウトするマクロ

Posted at
function html_comment() {
	var str = Editor.GetSelectedString(0);
	str = "<!--" + str + "-->";
	Editor.Ins.Text(str);
}
html_comment();

複数行が選択された場合に、各行に対して処理する場合はどうするか?
取得した文字列を、痴漢を使って行単位のデータに変換する。

#選択中のテキスト取得
var str = Editor.GetSelectedString(0);

var r = "";

#改行文字列で選択範囲を分割
var lines = str.split(/(¥r¥n|¥r|¥n)/);

#分割した文字列を行ごとに処理
for (var line in lines) {

	#行毎にコメントを挿入する。
	r += "<!-- " + lines[i] + "-->¥r¥n";
}
Editor.InsText(r);

#文字列のマッチング(指定した文字が含まれているかどうか)

var str="value_item = valueItem";
var re = new RegExp("(.*) += (.*)","i");
if (str.match(re)) {
	#文字列のパターンがマッチングしている場合
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?