- Published on
全角の日本語のかな文字を半角にするRubyスクリプト
- Authors
- Name
- Shou Arisaka / 有坂翔
全角の日本語のかな文字を半角にするRubyスクリプトを紹介します。
s="ゔぉー…"
argv = ARGV[0]
# s = argv
s = argv.gsub(//,'')
s.gsub!(/あ/,"ア")
s.gsub!(/い/,"イ")
s.gsub!(/う/,"ウ")
s.gsub!(/え/,"エ")
s.gsub!(/お/,"オ")
s.gsub!(/か/,"カ")
s.gsub!(/き/,"キ")
s.gsub!(/く/,"ク")
s.gsub!(/け/,"ケ")
s.gsub!(/こ/,"コ")
s.gsub!(/さ/,"サ")
s.gsub!(/し/,"シ")
s.gsub!(/す/,"ス")
s.gsub!(/せ/,"セ")
s.gsub!(/そ/,"ソ")
s.gsub!(/た/,"タ")
s.gsub!(/ち/,"チ")
s.gsub!(/つ/,"ツ")
s.gsub!(/て/,"テ")
s.gsub!(/と/,"ト")
s.gsub!(/な/,"ナ")
s.gsub!(/に/,"ニ")
s.gsub!(/ぬ/,"ヌ")
s.gsub!(/ね/,"ネ")
s.gsub!(/の/,"ノ")
s.gsub!(/は/,"ハ")
s.gsub!(/ひ/,"ヒ")
s.gsub!(/ふ/,"フ")
s.gsub!(/へ/,"ヘ")
s.gsub!(/ほ/,"ホ")
s.gsub!(/ま/,"マ")
s.gsub!(/み/,"ミ")
s.gsub!(/む/,"ム")
s.gsub!(/め/,"メ")
s.gsub!(/も/,"モ")
s.gsub!(/や/,"ヤ")
s.gsub!(/ゆ/,"ユ")
s.gsub!(/よ/,"ヨ")
s.gsub!(/ら/,"ラ")
s.gsub!(/り/,"リ")
s.gsub!(/る/,"ル")
s.gsub!(/れ/,"レ")
s.gsub!(/ろ/,"ロ")
s.gsub!(/わ/,"ワ")
s.gsub!(/を/,"ヲ")
s.gsub!(/ん/,"ン")
s.gsub!(/ゔ/,"ヴ")
s.gsub!(/が/,"ガ")
s.gsub!(/ぎ/,"ギ")
s.gsub!(/ぐ/,"グ")
s.gsub!(/げ/,"ゲ")
s.gsub!(/ご/,"ゴ")
s.gsub!(/ざ/,"ザ")
s.gsub!(/じ/,"ジ")
s.gsub!(/ず/,"ズ")
s.gsub!(/ぜ/,"ゼ")
s.gsub!(/ぞ/,"ゾ")
s.gsub!(/だ/,"ダ")
s.gsub!(/ぢ/,"ヂ")
s.gsub!(/づ/,"ヅ")
s.gsub!(/で/,"デ")
s.gsub!(/ど/,"ド")
s.gsub!(/ば/,"バ")
s.gsub!(/び/,"ビ")
s.gsub!(/ぶ/,"ブ")
s.gsub!(/べ/,"ベ")
s.gsub!(/ぼ/,"ボ")
s.gsub!(/ぱ/,"パ")
s.gsub!(/ぴ/,"ピ")
s.gsub!(/ぷ/,"プ")
s.gsub!(/ぺ/,"ペ")
s.gsub!(/ぽ/,"ポ")
s.gsub!(/ぁ/,"ァ")
s.gsub!(/ぃ/,"ィ")
s.gsub!(/ぅ/,"ゥ")
s.gsub!(/ぇ/,"ェ")
s.gsub!(/ぉ/,"ォ")
s.gsub!(/ゃ/,"ャ")
s.gsub!(/ゅ/,"ュ")
s.gsub!(/ょ/,"ョ")
s.gsub!(/っ/,"ッ")
s.gsub!(/ア/,"ア")
s.gsub!(/イ/,"イ")
s.gsub!(/ウ/,"ウ")
s.gsub!(/エ/,"エ")
s.gsub!(/オ/,"オ")
s.gsub!(/カ/,"カ")
s.gsub!(/キ/,"キ")
s.gsub!(/ク/,"ク")
s.gsub!(/ケ/,"ケ")
s.gsub!(/コ/,"コ")
s.gsub!(/サ/,"サ")
s.gsub!(/シ/,"シ")
s.gsub!(/ス/,"ス")
s.gsub!(/セ/,"セ")
s.gsub!(/ソ/,"ソ")
s.gsub!(/タ/,"タ")
s.gsub!(/チ/,"チ")
s.gsub!(/ツ/,"ツ")
s.gsub!(/テ/,"テ")
s.gsub!(/ト/,"ト")
s.gsub!(/ナ/,"ナ")
s.gsub!(/ニ/,"ニ")
s.gsub!(/ヌ/,"ヌ")
s.gsub!(/ネ/,"ネ")
s.gsub!(/ノ/,"ノ")
s.gsub!(/ハ/,"ハ")
s.gsub!(/ヒ/,"ヒ")
s.gsub!(/フ/,"フ")
s.gsub!(/ヘ/,"ヘ")
s.gsub!(/ホ/,"ホ")
s.gsub!(/マ/,"マ")
s.gsub!(/ミ/,"ミ")
s.gsub!(/ム/,"ム")
s.gsub!(/メ/,"メ")
s.gsub!(/モ/,"モ")
s.gsub!(/ヤ/,"ヤ")
s.gsub!(/ユ/,"ユ")
s.gsub!(/ヨ/,"ヨ")
s.gsub!(/ラ/,"ラ")
s.gsub!(/リ/,"リ")
s.gsub!(/ル/,"ル")
s.gsub!(/レ/,"レ")
s.gsub!(/ロ/,"ロ")
s.gsub!(/ワ/,"ワ")
s.gsub!(/ヲ/,"ヲ")
s.gsub!(/ン/,"ン")
s.gsub!(/ヴ/,"ヴ")
s.gsub!(/ガ/,"ガ")
s.gsub!(/ギ/,"ギ")
s.gsub!(/グ/,"グ")
s.gsub!(/ゲ/,"ゲ")
s.gsub!(/ゴ/,"ゴ")
s.gsub!(/ザ/,"ザ")
s.gsub!(/ジ/,"ジ")
s.gsub!(/ズ/,"ズ")
s.gsub!(/ゼ/,"ゼ")
s.gsub!(/ゾ/,"ゾ")
s.gsub!(/ダ/,"ダ")
s.gsub!(/ヂ/,"ヂ")
s.gsub!(/ヅ/,"ヅ")
s.gsub!(/デ/,"デ")
s.gsub!(/ド/,"ド")
s.gsub!(/バ/,"バ")
s.gsub!(/ビ/,"ビ")
s.gsub!(/ブ/,"ブ")
s.gsub!(/ベ/,"ベ")
s.gsub!(/ボ/,"ボ")
s.gsub!(/パ/,"パ")
s.gsub!(/ピ/,"ピ")
s.gsub!(/プ/,"プ")
s.gsub!(/ペ/,"ペ")
s.gsub!(/ポ/,"ポ")
s.gsub!(/ァ/,"ァ")
s.gsub!(/ィ/,"ィ")
s.gsub!(/ゥ/,"ゥ")
s.gsub!(/ェ/,"ェ")
s.gsub!(/ォ/,"ォ")
s.gsub!(/ャ/,"ャ")
s.gsub!(/ュ/,"ュ")
s.gsub!(/ョ/,"ョ")
s.gsub!(/ッ/,"ッ")
puts s
実行結果はこんな感じ。
$ ruby かな文字半角変換.rb ゔぉー…
ヴォー…