Created
June 29, 2012 06:42
-
-
Save hadashiA/3016299 to your computer and use it in GitHub Desktop.
Rubyで文字ード変換、未定義文字のみnkfをかます
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nkfはデフォルトで半角カナを全角カナにしてくれたり、未定義文字を良い感じにしてくれるので、String#encodeで変換できなかった文字はnkfに渡す。 | |
# -xを渡すと、半角全角変換はしない。 | |
str.encode('EUC-JP', Kconv.guess(str), fallback: -> char { NKF.nkf('-ex', char) }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment