Skip to content

Instantly share code, notes, and snippets.

@LuPoYi
Created June 25, 2016 09:39
Show Gist options
  • Save LuPoYi/587166f38c460d982601a42f6cdaaecf to your computer and use it in GitHub Desktop.
Save LuPoYi/587166f38c460d982601a42f6cdaaecf to your computer and use it in GitHub Desktop.
英數字半形轉全形
def convert_to_wide_word(text)
text.gsub(/[a-v]/){|a|(a.ord + 41608).chr('big5').encode('utf-8')}
.gsub(/[w-z]/){|a|(a.ord + 41673).chr('big5').encode('utf-8')}
.gsub(/[A-Z]/){|a|(a.ord + 41614).chr('big5').encode('utf-8')}
.gsub(/[0-9]/){|a|(a.ord + 41599).chr('big5').encode('utf-8')}
end
> convert_to_wide_word("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
=> "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL
MNOPQRSTUVWXYZ"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment