Skip to content

Instantly share code, notes, and snippets.

@uggds
Created January 18, 2015 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uggds/c0b7ce61f544d14b66f0 to your computer and use it in GitHub Desktop.
Save uggds/c0b7ce61f544d14b66f0 to your computer and use it in GitHub Desktop.
全角の英数字を半角に変換する
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