Created
January 18, 2015 13:21
-
-
Save uggds/c0b7ce61f544d14b66f0 to your computer and use it in GitHub Desktop.
全角の英数字を半角に変換する
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
StringBuilder sb = new StringBuilder(keyword); | |
for(int i = 0; i < sb.length(); i++) { | |
char c = sb.charAt(i); | |
if ('0' <= sb.charAt(i) && '9' >= sb.charAt(i)) { | |
sb.setCharAt(i, (char)(c - '0' + '0')); | |
} else if ('A' <= sb.charAt(i) && 'Z' >= sb.charAt(i)) { | |
sb.setCharAt(i, (char)(c - 'A' + 'A')); | |
} else if ('a' <= sb.charAt(i) && 'z' >= sb.charAt(i)) { | |
sb.setCharAt(i, (char) (c - 'a' + 'a')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment