LoginSignup
0
3

More than 5 years have passed since last update.

powershellでひらがなをローマ字に変換する関数

Last updated at Posted at 2017-07-14

新入社員用のユーザ用IDを考えるのが面倒だったので作成。

kanaToAlphabet("おおしまゆうこ") ってな感じで指定してもらうと

oshimayukoてな感じで返してくれます。

function kanaToAlphabet($string) {
  $convertString = $string
  #------
  $convertString = $convertString -replace "ぎゃ","gya"
  $convertString = $convertString -replace "ぎゅ","gyu"
  $convertString = $convertString -replace "ぎょ","gyo"
  $convertString = $convertString -replace "きゃ","kya"
  $convertString = $convertString -replace "きゅ","kyu"
  $convertString = $convertString -replace "きょ","kyo"
  $convertString = $convertString -replace "しゃ","sha"
  $convertString = $convertString -replace "しゅ","syu"
  $convertString = $convertString -replace "しょ","syo"
  $convertString = $convertString -replace "ちゃ","tya"
  $convertString = $convertString -replace "ちゅ","tyu"
  $convertString = $convertString -replace "ちょ","tyo"
  $convertString = $convertString -replace "ひゃ","hya"
  $convertString = $convertString -replace "ひゅ","hyu"
  $convertString = $convertString -replace "ひょ","hyo"
  $convertString = $convertString -replace "みゃ","mya"
  $convertString = $convertString -replace "みゅ","my"
  $convertString = $convertString -replace "みょ","myo"
  $convertString = $convertString -replace "じゃ","ja"
  $convertString = $convertString -replace "じゅ","jyu"
  $convertString = $convertString -replace "じょ","jyo"
  $convertString = $convertString -replace "ぢゃ","dya"
  $convertString = $convertString -replace "ぢゅ","dyu"
  $convertString = $convertString -replace "ぢょ","dyo"
  $convertString = $convertString -replace "びゃ","pya"
  $convertString = $convertString -replace "びゅ","pyu"
  $convertString = $convertString -replace "びょ","pyo"
  $convertString = $convertString -replace "りゃ","rya"
  $convertString = $convertString -replace "りゅ","ryu"
  $convertString = $convertString -replace "りょ","ryo"
  #------
  $convertString = $convertString -replace "あ","a"
  $convertString = $convertString -replace "い","i"
  $convertString = $convertString -replace "う","u"
  $convertString = $convertString -replace "え","e"
  $convertString = $convertString -replace "お","o"
  $convertString = $convertString -replace "か","ka"
  $convertString = $convertString -replace "き","ki"
  $convertString = $convertString -replace "く","ku"
  $convertString = $convertString -replace "け","ke"
  $convertString = $convertString -replace "こ","ko"
  $convertString = $convertString -replace "さ","sa"
  $convertString = $convertString -replace "し","shi"
  $convertString = $convertString -replace "す","su"
  $convertString = $convertString -replace "せ","se"
  $convertString = $convertString -replace "そ","so"
  $convertString = $convertString -replace "た","ta"
  $convertString = $convertString -replace "ち","chi"
  $convertString = $convertString -replace "つ","tsu"
  $convertString = $convertString -replace "て","te"
  $convertString = $convertString -replace "と","to"
  $convertString = $convertString -replace "な","na"
  $convertString = $convertString -replace "に","ni"
  $convertString = $convertString -replace "ぬ","nu"
  $convertString = $convertString -replace "ね","ne"
  $convertString = $convertString -replace "の","no"
  $convertString = $convertString -replace "は","ha"
  $convertString = $convertString -replace "ひ","hi"
  $convertString = $convertString -replace "ふ","fu"
  $convertString = $convertString -replace "へ","he"
  $convertString = $convertString -replace "ほ","ho"
  $convertString = $convertString -replace "ま","ma"
  $convertString = $convertString -replace "み","mi"
  $convertString = $convertString -replace "む","mu"
  $convertString = $convertString -replace "め","me"
  $convertString = $convertString -replace "も","mo"
  $convertString = $convertString -replace "ら","ra"
  $convertString = $convertString -replace "り","ri"
  $convertString = $convertString -replace "る","ru"
  $convertString = $convertString -replace "れ","re"
  $convertString = $convertString -replace "ろ","ro"
  $convertString = $convertString -replace "や","ya"
  $convertString = $convertString -replace "ゆ","yu"
  $convertString = $convertString -replace "よ","yo"
  $convertString = $convertString -replace "わ","wa"
  $convertString = $convertString -replace "を","wo"
  $convertString = $convertString -replace "ん","n"
  $convertString = $convertString -replace "が","ga"
  $convertString = $convertString -replace "ぎ","gi"
  $convertString = $convertString -replace "ぐ","gu"
  $convertString = $convertString -replace "げ","ge"
  $convertString = $convertString -replace "ご","go"
  $convertString = $convertString -replace "ざ","za"
  $convertString = $convertString -replace "じ","ji"
  $convertString = $convertString -replace "ず","zu"
  $convertString = $convertString -replace "ぜ","ze"
  $convertString = $convertString -replace "ぞ","zo"
  $convertString = $convertString -replace "だ","da"
  $convertString = $convertString -replace "ぢ","di"
  $convertString = $convertString -replace "づ","du"
  $convertString = $convertString -replace "で","de"
  $convertString = $convertString -replace "ど","do"
  $convertString = $convertString -replace "ば","ba"
  $convertString = $convertString -replace "び","bi"
  $convertString = $convertString -replace "ぶ","bu"
  $convertString = $convertString -replace "べ","be"
  $convertString = $convertString -replace "ぼ","bo"
  $convertString = $convertString -replace "ぱ","pa"
  $convertString = $convertString -replace "ぴ","pi"
  $convertString = $convertString -replace "ぷ","pu"
  $convertString = $convertString -replace "ぺ","pe"
  $convertString = $convertString -replace "ぽ","po"
  #-----
  $convertString = $convertString -replace "oo","o" #「大泉」等に対応
  $convertString = $convertString -replace "ou","o" #「伊藤」等に対応
  $convertString = $convertString -replace "uu","u" #「優子」等に対応
  #-----
  Write-Output $convertString
}
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3