Skip to content

Instantly share code, notes, and snippets.

@indiejoseph
Created May 24, 2014 10:35
Show Gist options
  • Select an option

  • Save indiejoseph/11aa445df848e0d805b0 to your computer and use it in GitHub Desktop.

Select an option

Save indiejoseph/11aa445df848e0d805b0 to your computer and use it in GitHub Desktop.
全角轉半角
DBC2SBC = (str, flag) ->
result=''
return no if str.length <= 0
for i in [0...str.length]
str1=str.charCodeAt(i)
if !flag
if str1 < 127
result += String.fromCharCode str.charCodeAt(i) + 65248
else
result += String.fromCharCode str.charCodeAt(i)
else
if str1 > 126
result += String.fromCharCode str.charCodeAt(i) - 65248
else
result += String.fromCharCode str.charCodeAt(i)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment