Created
May 24, 2014 10:35
-
-
Save indiejoseph/11aa445df848e0d805b0 to your computer and use it in GitHub Desktop.
全角轉半角
This file contains hidden or 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
| 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