|
vbs郵便番号データの変換ツール
何故か半角カナが使われている郵便番号データ。
データとして半角カタカナは不便なので全角カタカナに変換するツールを作りました。
手元で手軽に使える環境がVBScriptの環境しかなかったので、vbsで作成しています。
とりあえず使える物を作ったので、かなりしょぼいです。
(処理速度等を全然考慮していませんが、Pen4 2Ghzで一分くらいです)
本当は、perlかjavaか何かで正規表現を使って処理した方が良いのですがね。
あと、エンコードの指定とか。時間があれば、vbsで半角全角カタカナ変換関数考えて見ます。
strconvだと、英数字まで全角に変換してしまったはず。
ダウンロードはこちら。inFilePathとoutFilePathを適当に変えて使ってください。
ついでに、郵便データをインポートする為にテーブル定義のDDLを作ってみました。
主キー等が必要な場合、適当にユニークIDを作ってください。
postal=convert.vbs
Option Explicit
Dim fso
Dim inFilePath
Dim outFilePath
Dim inFile
Dim outFile
Dim line_str
inFilePath = "\temp\postal.csv"
outFilePath = "\temp\postal2.csv"
Set fso = CreateObject("Scripting.FileSystemObject")
Set inFile = fso.OpenTextFile(inFilePath)
Set outFile = fso.CreateTextFile(outFilePath)
Do Until inFile.AtEndOfStream
line_str = inFile.ReadLine
line_str = Han2Zen(line_str)
outFile.write line_str & vbCrLF
Loop
inFile.close
outFile.close
Set inFile = nothing
Set outFile = nothing
Set fso = nothing
Function Han2Zen(str)
str = replace(str,"ガ","ガ")
str = replace(str,"ギ","ギ")
str = replace(str,"グ","グ")
str = replace(str,"ゲ","ゲ")
str = replace(str,"ゴ","ゴ")
str = replace(str,"ザ","ザ")
str = replace(str,"ジ","ジ")
str = replace(str,"ズ","ズ")
str = replace(str,"ゼ","ゼ")
str = replace(str,"ゾ","ゾ")
str = replace(str,"ダ","ダ")
str = replace(str,"ヂ","ヂ")
str = replace(str,"ヅ","ヅ")
str = replace(str,"デ","デ")
str = replace(str,"ド","ド")
str = replace(str,"バ","バ")
str = replace(str,"ビ","ビ")
str = replace(str,"ブ","ブ")
str = replace(str,"ベ","ベ")
str = replace(str,"ボ","ボ")
str = replace(str,"パ","パ")
str = replace(str,"ピ","ピ")
str = replace(str,"プ","プ")
str = replace(str,"ペ","ペ")
str = replace(str,"ポ","ポ")
str = replace(str,"ア","ア")
str = replace(str,"イ","イ")
str = replace(str,"ウ","ウ")
str = replace(str,"エ","エ")
str = replace(str,"オ","オ")
str = replace(str,"カ","カ")
str = replace(str,"キ","キ")
str = replace(str,"ク","ク")
str = replace(str,"ケ","ケ")
str = replace(str,"コ","コ")
str = replace(str,"サ","サ")
str = replace(str,"シ","シ")
str = replace(str,"ス","ス")
str = replace(str,"セ","セ")
str = replace(str,"ソ","ソ")
str = replace(str,"タ","タ")
str = replace(str,"チ","チ")
str = replace(str,"ツ","ツ")
str = replace(str,"テ","テ")
str = replace(str,"ト","ト")
str = replace(str,"ナ","ナ")
str = replace(str,"ニ","ニ")
str = replace(str,"ヌ","ヌ")
str = replace(str,"ネ","ネ")
str = replace(str,"ノ","ノ")
str = replace(str,"ハ","ハ")
str = replace(str,"ヒ","ヒ")
str = replace(str,"フ","フ")
str = replace(str,"ヘ","ヘ")
str = replace(str,"ホ","ホ")
str = replace(str,"マ","マ")
str = replace(str,"ミ","ミ")
str = replace(str,"ム","ム")
str = replace(str,"メ","メ")
str = replace(str,"モ","モ")
str = replace(str,"ヤ","ヤ")
str = replace(str,"ユ","ユ")
str = replace(str,"ヨ","ヨ")
str = replace(str,"ラ","ラ")
str = replace(str,"リ","リ")
str = replace(str,"ル","ル")
str = replace(str,"レ","レ")
str = replace(str,"ロ","ロ")
str = replace(str,"ワ","ワ")
str = replace(str,"ヲ","ヲ")
str = replace(str,"ン","ン")
str = replace(str,"ァ","ァ")
str = replace(str,"ィ","ィ")
str = replace(str,"ゥ","ゥ")
str = replace(str,"ェ","ェ")
str = replace(str,"ォ","ォ")
str = replace(str,"ヵ","ヵ")
str = replace(str,"ヶ","ヶ")
str = replace(str,"ッ","ッ")
str = replace(str,"ャ","ャ")
str = replace(str,"ュ","ュ")
str = replace(str,"ョ","ョ")
Han2Zen = str
End Function
【参考にしたサイト】
ゆうびんホームページ 郵便番号等のダウンロード
|