「
テキスト変換
」を編集中 (節単位)
ナビゲーションに移動
検索に移動
警告:
ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。
ログイン
または
アカウントを作成
すれば、あなたの編集はその利用者名とともに表示されるほか、さまざまなメリットもあります。
スパム攻撃防止用のチェックです。 決して、ここには、値の入力は
しない
でください!
== 拡張コード == '''ご自由に追加してください!''' 2つ並んでいますが、機能は全く同じです。 管理のしやすさから、1行にまとめている方をお勧めします。 === 空白削除 === <syntaxhighlight lang="javascript" copy> f[f.length] = [ "空白削除", function(f){ f[f.length] = [ "行頭の空白文字を削除", "", function(a){return a.replace(/^[ \t ]+/mg,"")} ]; f[f.length] = [ "行末の空白文字を削除", "", function(a){return a.replace(/[ \t ]+$/mg,"")} ]; f[f.length] = [ "行頭・行末の空白文字を削除", "", function(a){return a.replace(/^[ \t ]+|[ \t ]+$/mg,"")} ]; f[f.length] = [ "空白行を削除", "L", function(text){ return text==""?null:text} ]; f[f.length] = [ "カンマ前後の空白文字を削除", "", function(a){return a.replace(/^[ \t ]+|[ \t ]+$/mg,"").replace(/[ \t ]*,[ \t ]*/mg,",")} ]; }]; </syntaxhighlight> <syntaxhighlight lang="javascript" copy> f[f.length] = { title:"空白削除", group:function(f){ f[f.length] = { title:"行頭の空白文字を削除", replace:function(text){ return text.replace(/^[ \t ]+/mg, "") } }; f[f.length] = { title:"行末の空白文字を削除", replace:function(text){ return text.replace(/[ \t ]+$/mg, "") } }; f[f.length] = { title:"行頭・行末の空白文字を削除", replace:function(text){ return text.replace(/^[ \t ]+|[ \t ]+$/mg, "") } }; f[f.length] = { title:"空白行を削除", replaceL:function(text){ return text=="" ? null : text } }; f[f.length] = { title:"カンマ前後の空白文字を削除", replace:function(text){ return text.replace(/^[ \t ]+|[ \t ]+$/mg, "").replace(/[ \t ]*,[ \t ]*/mg, ","); } }; } }; </syntaxhighlight> === 文字変換 === <syntaxhighlight lang="javascript" copy> f[f.length] = [ "文字変換", function(f){ f[f.length] = [ "大文字に変換", "", function(a){return a.toUpperCase()} ]; f[f.length] = [ "小文字に変換", "", function(a){return a.toLowerCase()} ]; f[f.length] = [ "全角⇒半角", function(f){ f[f.length] = [ "英字", "", function(a){return a.replace(/[A-Za-z]/mg,function(s){return String.fromCharCode(s.charCodeAt(0)-0xFEE0)})} ]; f[f.length] = [ "数字", "", function(a){return a.replace(/[0-9]/mg,function(s){return String.fromCharCode(s.charCodeAt(0)-0xFEE0)})} ]; f[f.length] = [ "英数字", "", function(a){return a.replace(/[A-Za-z0-9]/mg,function(s){return String.fromCharCode(s.charCodeAt(0)-0xFEE0)})} ]; }]; f[f.length] = [ "半角⇒全角", function(f){ f[f.length] = [ "英字", "", function(a){return a.replace(/[A-Za-z]/mg,function(s){return String.fromCharCode(s.charCodeAt(0)+0xFEE0)})} ]; f[f.length] = [ "数字", "", function(a){return a.replace(/[0-9]/mg,function(s){return String.fromCharCode(s.charCodeAt(0)+0xFEE0)})} ]; f[f.length] = [ "英数字", "", function(a){return a.replace(/[A-Za-z0-9]/mg,function(s){return String.fromCharCode(s.charCodeAt(0)+0xFEE0)})} ]; }]; f[f.length] = [ "アラビア数字⇒漢数字", "", function(a){return a.replace(/[0-9]/mg,function(s){return String.fromCharCode(s.charCodeAt(0)-0xFEE0)}).replace(/[0-9]/mg,function(s){return"〇一二三四五六七八九".substr(Number(s),1)})} ]; }]; </syntaxhighlight> <syntaxhighlight lang="javascript" copy> f[f.length] = { title:"文字変換", group:function(f){ f[f.length] = { title:"大文字に変換", replace:function(text){ return text.toUpperCase() } }; f[f.length] = { title:"小文字に変換", replace:function(text){ return text.toLowerCase() } }; f[f.length] = { title:"全角⇒半角", group:function(f){ f[f.length] = { title:"英字", replace:function(text){ return text.replace(/[A-Za-z]/mg, function(s){ return String.fromCharCode(s.charCodeAt(0) - 0xFEE0) }) } }; f[f.length] = { title:"数字", replace:function(text){ return text.replace(/[0-9]/mg, function(s){ return String.fromCharCode(s.charCodeAt(0) - 0xFEE0) }) } }; f[f.length] = { title:"英数字", replace:function(text){ return text.replace(/[A-Za-z0-9]/mg, function(s){ return String.fromCharCode(s.charCodeAt(0) - 0xFEE0) }) } }; } }; f[f.length] = { title:"半角⇒全角", group:function(f){ f[f.length] = { title:"英字", replace:function(text){ return text.replace(/[A-Za-z]/mg, function(s){ return String.fromCharCode(s.charCodeAt(0) + 0xFEE0) }) } }; f[f.length] = { title:"数字", replace:function(text){ return text.replace(/[0-9]/mg, function(s){ return String.fromCharCode(s.charCodeAt(0) + 0xFEE0) }) } }; f[f.length] = { title:"英数字", replace:function(text){ return text.replace(/[A-Za-z0-9]/mg, function(s){ return String.fromCharCode(s.charCodeAt(0) + 0xFEE0) }) } }; } }; f[f.length] = { title:"アラビア数字⇒漢数字", replace:function(text){ return text.replace(/[0-9]/mg, function(s){ return String.fromCharCode(s.charCodeAt(0) - 0xFEE0) }).replace(/[0-9]/mg, function(s){ return "〇一二三四五六七八九".substr(Number(s), 1); }); } }; } }; </syntaxhighlight> === ソート === 「[[昇順で並び替え]]」「[[降順で並び替え]]」の移植です。 <syntaxhighlight lang="javascript" copy> f[f.length] = [ "ソート", function(f){ f[f.length] = [ "昇順ソート(文字列)", "S", function(a){return a.split("\n").sort().join("\n")} ]; f[f.length] = [ "降順ソート(文字列)", "S", function(a){return a.split("\n").sort().reverse().join("\n")} ]; }]; </syntaxhighlight> <syntaxhighlight lang="javascript" copy> f[f.length] = { title:"ソート", group:function(f){ f[f.length] = { title:"昇順ソート(文字列)", replaceS:function(text){ return text.split("\n").sort().join("\n") } }; f[f.length] = { title:"降順ソート(文字列)", replaceS:function(text){ return text.split("\n").sort().reverse().join("\n") } }; } }; </syntaxhighlight> === 行操作 === 「[[連続する重複行を削除]]」の移植を含みます。 <syntaxhighlight lang="javascript" copy> f[f.length] = [ "行操作", function(f){ f[f.length] = [ "文字列追加", function(f){ f[f.length] = [ "先頭", "L", (function(b){var c=null;return function(a){if(!c){if(!(c=Prompt("追加する文字列を入力してください。",""))){Quit()}}return c+a}})() ]; f[f.length] = [ "末尾", "L", (function(b){var c=null;return function(a){if(!c){if(!(c=Prompt("追加する文字列を入力してください。",""))){Quit()}}return a+c}})() ]; }]; f[f.length] = [ "行削除", function(f){ f[f.length] = [ "含む行(文字列)", "L", (function(b){var c=null;return function(a){if(!c){if(!(c=Prompt("検索文字列",""))){Quit()}}return a.indexOf(c)>=0?null:a}})() ]; f[f.length] = [ "含む行(正規表現)", "L", (function(b){var c=null;return function(a){if(!c){if(!(c=Prompt("正規表現",""))){Quit()}else{c=new RegExp(c)}}return c.test(a)?null:a}})() ]; f[f.length] = [ "含まない行(文字列)", "L", (function(b){var c=null;return function(a){if(!c){if(!(c=Prompt("検索文字列",""))){Quit()}}return a.indexOf(c)>=0?a:null}})() ]; f[f.length] = [ "含まない行(正規表現)", "L", (function(b){var c=null;return function(a){if(!c){if(!(c=Prompt("正規表現",""))){Quit()}else{c=new RegExp(c)}}return c.test(a)?a:null}})() ]; f[f.length] = [ "連続する重複を削除", "S", function(a){a=a.split("\n");var b=[a[0]];for(var i=1;i<a.length;i++){if(a[i]!==a[i-1]){b.push(a[i])}}return b.join("\n")} ]; f[f.length] = [ "重複行を削除", "S", function(a){a=a.split("\n");var b=[],map={};for(var i=0;i<a.length;i++){if(!map[a[i]]){map[a[i]]=true;b.push(a[i])}}return b.join("\n")} ]; }]; }]; </syntaxhighlight> <syntaxhighlight lang="javascript" copy> f[f.length] = { title:"行操作", group:function(f){ f[f.length] = { title:"文字列追加", group:function(f){ f[f.length] = { title:"先頭", replaceL:(function(text){ var input = null; return function(text){ if (!input){ if(!(input=Prompt("追加する文字列を入力してください。",""))){Quit()} } return input + text; } })() }; f[f.length] = { title:"末尾", replaceL:(function(text){ var input = null; return function(text){ if (!input){ if(!(input=Prompt("追加する文字列を入力してください。",""))){Quit()} } return text + input; } })() }; } }; f[f.length] = { title:"行削除", group:function(f){ f[f.length] = { title:"含む行(文字列)", replaceL:(function(text){ var input = null; return function(text){ if (!input){ if(!(input=Prompt("検索文字列", ""))){Quit()} } return text.indexOf(input) >= 0 ? null : text; } })() }; f[f.length] = { title:"含む行(正規表現)", replaceL:(function(text){ var input = null; return function(text){ if (!input){ if(!(input=Prompt("正規表現", ""))){Quit()}else{input=new RegExp(input)} } return input.test(text) ? null : text; } })() }; f[f.length] = { title:"含まない行(文字列)", replaceL:(function(text){ var input = null; return function(text){ if (!input){ if(!(input=Prompt("検索文字列", ""))){Quit()} } return text.indexOf(input) >= 0 ? text : null; } })() }; f[f.length] = { title:"含まない行(正規表現)", replaceL:(function(text){ var input = null; return function(text){ if (!input){ if(!(input=Prompt("正規表現", ""))){Quit()}else{input=new RegExp(input)} } return input.test(text) ? text : null; } })() }; f[f.length] = { title:"連続する重複を削除", replaceS:function(text){ text = text.split("\n"); var result = [text[0]]; for (var i=1; i<text.length; i++) { if (text[i] !== text[i-1]) { result.push(text[i]); } } return result.join("\n"); } }; f[f.length] = { title:"重複行を削除", replaceS:function(text){ text = text.split("\n"); var result = [], map = {}; for (var i=0; i<text.length; i++) { if (!map[text[i]]) { map[text[i]] = true; result.push(text[i]); } } return result.join("\n"); } }; } }; } }; </syntaxhighlight> === グルーピング === 選択範囲を簡易的にグルーピングします。 <syntaxhighlight lang="javascript" copy> f[f.length] = [ "機能のグルーピング", "S", function(a){var b=Prompt("グループ名","");if(!b){Quit()}var c=a.match(/^\s*/);var d="\t";return c+'f[f.length] = [ "'+b+'", function(f){\n'+d+a.split("\n").join("\n"+d)+"\n"+c+"}];"} ]; </syntaxhighlight> <syntaxhighlight lang="javascript" copy> f[f.length] = { title:"機能のグルーピング", replaceS:function(text){ var group = Prompt("グループ名", ""); if (!group) { Quit(); } var indent = text.match(/^\s*/); var tab = "\t"; // インデント方式。タブでない場合はその分の空白を代入しておく。 return indent + 'f[f.length] = [ "' + group + '", function(f){\n'+ tab + text.split("\n").join("\n" + tab) + "\n" + indent + "}];"; } }; </syntaxhighlight> === BASE64エンコード(Unicode) === <syntaxhighlight lang="javascript" copy> f[f.length] = { title:"BASE64エンコード(Unicode)", replace:function(text){ var map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""); var Ch = function(n){ return n<text.length ? text.charCodeAt(n) : 0 }; var len = text.length, pad = len % 3, s = ""; for (var i=0; i<len; i+=3) { var tmp = (Ch(i)<<16) | (Ch(i+1)<<8) | Ch(i+2); s += map[(tmp>>>18)&0x3F] + map[(tmp>>>12)&0x3F] + map[(tmp>>>6)&0x3F] + map[tmp&0x3F]; } if (pad) { s = s.substring(0, s.length-(3-pad)) + "===".substring(pad) } return s; } }; </syntaxhighlight>
編集内容の要約:
MeryWikiへの投稿はすべて、他の投稿者によって編集、変更、除去される場合があります。 自分が書いたものが他の人に容赦なく編集されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください(詳細は
MeryWiki:著作権
を参照)。
著作権保護されている作品は、許諾なしに投稿しないでください!
このページを編集するには、下記の数式を計算してその答えを欄に入力してください (
ヘルプ
):
いちたすには =
キャンセル
編集ヘルプ
(新しいウィンドウで開きます)
スポンサーリンク
ナビゲーション メニュー
個人用ツール
ログインしていません
トーク
投稿記録
アカウント作成
ログイン
名前空間
ページ
議論
日本語
表示
閲覧
編集
履歴表示
その他
検索
スポンサーリンク
スポンサーリンク
案内
メインページ
ヘルプ
よくある質問
マクロリファレンス
マクロライブラリ
プラグインライブラリ
構文ファイル
テーマ
寄付・開発支援
練習用ページ
開発室
開発者のブログ
ツール
スポンサーリンク