機能 ショートカットキー
リファレンス(参考URL)一覧へ移動 R
記事URLをMarkDownとしてコピー Ctrl+M
前のコードタグへ移動 Ctrl+←
次のコードタグへ移動 Ctrl+→
ヘルプを表示・非表示 H
Tips
- ショートカットキーは記事上で有効です。ヘッダー/フッター付近では機能しないことがあります。
- コードタグ移動機能がうまく動かないときは、Shift+F5でページを更新してみてください。
- このウィンドウを閉じるには、Hキーをもう一度押してください

全角の日本語のかな文字を半角にするRubyスクリプト

AD

プログラミング

皆さん「何言ってんだこいつ…」

はい、こういうことです。

アーイキソ… → アーイキソ…

これをGoogle日本語入力で変換する方法を僕は知りません。できるなら教えてください。オナシャス!

では、こちらです。


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

実行結果はこんな感じ。

yuis@DESKTOP-UHU8FSH:/mnt/c/pg/zenkaku_henkan$ ruby /mnt/c/pg/zenkaku_henkan/かな文字半角変換.rb カンノミホ…
カンノミホ…
yuis@DESKTOP-UHU8FSH:/mnt/c/pg/zenkaku_henkan$ ruby /mnt/c/pg/zenkaku_henkan/かな文字半角変換.rb  かんのみほ…
カンノミホ…
yuis@DESKTOP-UHU8FSH:/mnt/c/pg/zenkaku_henkan$ ruby /mnt/c/pg/zenkaku_henkan/かな文字半角変換.rb ゔぉー…
ヴォー…

チカレタ…(作業時間3時間並感)

SPONSOR

オンラインブートキャンプ全12コースの「ウケ放題」 AD

コメントを残す

Close Menu