【VBScript】ひらがなをカタカナに、カタカナをひらがなに変換する

VBScript

ひらがなをカタカナに変換する

VBScriptで、ひらがなをカタカナに変換する方法です。※コピー貼り付けでそのまま使用できます

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


'変換する関数
Function ConvertStr(SrcStr, BefAry, AftAry)
  Dim CnvStr
  CnvStr = SrcStr
  For i=0 To UBound(BefAry)
    CnvStr = Replace(CnvStr, BefAry(i), AftAry(i))
  Next
  ConvertStr = CnvStr
End Function


'実行方法
'ConvertStr("変換したい文字列", hiragana, katakana)


'実行例
msgbox ConvertStr("あいうえお", hiragana, katakana) 
'結果:アイウエオ

 

 

カタカナをひらがなに変換する

VBScriptで、カタカナをひらがなに変換する方法です。※コピー貼り付けでそのまま使用できます

尚、半角カタカナは全角のひらがなに変換します。

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


'変換する関数
Function ConvertStr(SrcStr, BefAry, AftAry)
  Dim CnvStr
  CnvStr = SrcStr
  For i=0 To UBound(BefAry)
    CnvStr = Replace(CnvStr, BefAry(i), AftAry(i))
  Next
  ConvertStr = CnvStr
End Function


'実行方法
'ConvertStr(ConvertStr("変換したい文字列", hankata, katakana), katakana, hiragana)


'実行例
msgbox ConvertStr(ConvertStr("アイウエオカキクケコ", hankata, katakana), katakana, hiragana)
'結果:あいうえおかきくけこ