출처 : http://java.akjava.com/library/kanagana
public class Hiragana {
public static final char KATAKANA_SMALL_A=12449;
public static final char KATAKANA_NN=12531;
public static final char HIRAGANA_SMALL_A=12353;
public static final char HIRAGANA_NN=12531;
public static String kanaToGana(String s) {
StringBuffer sb = new StringBuffer(s);
for (int i = 0; i < sb.length(); i++) {
char c = sb.charAt(i);
if (c >= KATAKANA_SMALL_A && c <= KATAKANA_NN) {
sb.setCharAt(i, (char)(c - KATAKANA_SMALL_A +HIRAGANA_SMALL_A));
}
}
return sb.toString();
}
public static String ganaToKana(String s) {
StringBuffer sb = new StringBuffer(s);
for (int i = 0; i < sb.length(); i++) {
char c = sb.charAt(i);
if (c >= HIRAGANA_SMALL_A && c <= HIRAGANA_NN) {
sb.setCharAt(i, (char)(c - HIRAGANA_SMALL_A + KATAKANA_SMALL_A));
}
}
return sb.toString();
}
public static void main(String[] args){
String kana = "かな";
String gana = "カナ";
// String ret = kanaToGana(gana);
String ret = ganaToKana(kana);
System.out.println(ret);
}
}
위의 알고리즘으로 히라가나, 카타가나 변환이 간단히 됨.
댓글 없음 :
댓글 쓰기