取得した変数をひらがなからカタカナにする方法【Javascript】

名称未設定-1

取得した変数をひらがなからカタカナにする方法【Javascript】

取得した変数「ひらがな」を「カタカナ」に変更する際には、

テキストの置き換えだけではなく、Javascriptを使用しての変換を行うことで、

簡単に変数を置き換えることが出来ます。

アクション【変数の変換】→【JavaScriptを使用して変換】のスクリプト内に下記をペーストすることで、

指定した変数を変換することが出来ます。

OUTPUT = tozenkaku(INPUT);
function tozenkaku(thismoji){
//配列を用意する
hankaku = new Array(“が”, “ぎ”, “ぐ”, “げ”, “ご”, “ざ”, “じ”, “ず”, “ぜ”, “ぞ”, “だ”, “ぢ”, “づ”, “で”, “ど”, “ば”, “ぱ”, “び”, “ぴ”, “ぶ”, “ぷ”, “べ”, “ぺ”, “ぼ”, “ぽ”, “ゔ”, “ぁ”, “あ”, “ぃ”, “い”, “ぅ”, “う”, “ぇ”, “え”, “ぉ”, “お”, “か”, “き”, “く”, “け”, “こ”, “さ”, “し”, “す”, “せ”, “そ”, “た”, “ち”, “っ”, “つ”, “て”, “と”, “な”, “に”, “ぬ”, “ね”, “の”, “は”, “ひ”, “ふ”, “へ”, “ほ”, “ま”, “み”, “む”, “め”, “も”, “ゃ”, “や”, “ゅ”, “ゆ”, “ょ”, “よ”, “ら”, “り”, “る”, “れ”, “ろ”, “わ”, “を”, “ん”, “。”, “「”, “」”, “、”, “・”, “ー”);
zenkaku = new Array(“ガ”, “ギ”, “グ”, “ゲ”, “ゴ”, “ザ”, “ジ”, “ズ”, “ゼ”, “ゾ”, “ダ”, “ヂ”, “ヅ”, “デ”, “ド”, “バ”, “パ”, “ビ”, “ピ”, “ブ”, “プ”, “ベ”, “ペ”, “ボ”, “ポ”, “ヴ”, “ァ”, “ア”, “ィ”, “イ”, “ゥ”, “ウ”, “ェ”, “エ”, “ォ”, “オ”, “カ”, “キ”, “ク”, “ケ”, “コ”, “サ”, “シ”, “ス”, “セ”, “ソ”, “タ”, “チ”, “ッ”, “ツ”, “テ”, “ト”, “ナ”, “ニ”, “ヌ”, “ネ”, “ノ”, “ハ”, “ヒ”, “フ”, “ヘ”, “ホ”, “マ”, “ミ”, “ム”, “メ”, “モ”, “ャ”, “ヤ”, “ュ”, “ユ”, “ョ”, “ヨ”, “ラ”, “リ”, “ル”, “レ”, “ロ”, “ワ”, “ヲ”, “ン”, “。”, “「”, “」”, “、”, “・”, “ー”, “゛”, “゜”);
//変換開始
for (i=0; i<=88; i++) { //89文字あるのでその分だけ繰り返す
while (thismoji.indexOf(hankaku[i]) >= 0){ //該当する全角カナがなくなるまで繰り返す
thismoji = thismoji.replace(hankaku[i], zenkaku[i]); //全角カナに対応する半角カナに置換する
}
}
return thismoji; //変換が終わったら表示
}