Skip to content

Instantly share code, notes, and snippets.

@stknohg
Created December 3, 2015 09:08
Show Gist options
  • Save stknohg/175ebd1cc3eb8a750dd9 to your computer and use it in GitHub Desktop.
Save stknohg/175ebd1cc3eb8a750dd9 to your computer and use it in GitHub Desktop.
-Replace演算子でコールバックが使えるか試した結果
# 文字列置換時にコールバックを使う
$RegEx = [Regex]"\p{IsHiragana}"
$RegEx.Replace("ざっくりひらがなをカタカナに変換する。", { [char]([int]($args[0].value[0])+0x60) } )
#
# 変換結果 → ザックリヒラガナヲカタカナニ変換スル。
#
# -Replace演算子ではスクリプトブロックを指定できたもののコールバックは使えなかった
# 単純にToStringした結果を渡してるだけっぽい。
"ざっくりひらがなをカタカナに変換する。" -replace "(?<kana>\p{IsHiragana})", { [char]([int](${kana})+0x60) }
#
# 変換結果 → [char]([int](ざ)+0x60) [char]([int](っ)+0x60) [char]([int](く)+0x60) [char]([int](り)+0x60) [char]([int](ひ)+0x60) [char]([int](ら)+0x60) [char]([int](が)+0x60) [char]([int](な)+0x60) [char]([int](を)+0x60) カタカナ [char]([int](に)+0x60) 変換 [char]([int](す)+0x60) [char]([int](る)+0x60) 。
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment