[Java] 한글체크
class CharTest
{
// 한글인가?
public static boolean isHangul(char c)
{
return isHangulSyllables(c) || isHangulJamo(c) || isHangulCompatibilityJamo(c);
}
// 완성된 한글인가? 참조: http://www.unicode.org/charts/PDF/UAC00.pdf
public static boolean isHangulSyllables(char c)
{
// return (c >= (char) 0xAC00 && c <= (char) 0xD7AF);
return (c >= (char) 0xAC00 && c <= (char) 0xD7A3);
}
// (현대 및 고어) 한글 자모? 참조: http://www.unicode.org/charts/PDF/U1100.pdf
public static boolean isHangulJamo(char c)
{
// return (c >= (char) 0x1100 && c <= (char) 0x11FF);
return (c >= (char) 0x1100 && c <= (char) 0x1159)
|| (c >= (char) 0x1161 && c <= (char) 0x11A2)
|| (c >= (char) 0x11A8 && c <= (char) 0x11F9);
}
// (현대 및 고어) 한글 자모? 참조: http://www.unicode.org/charts/PDF/U3130.pdf
public static boolean isHangulCompatibilityJamo(char c)
{
// return (c >= (char) 0x3130 && c <= (char) 0x318F);
return (c >= (char) 0x3131 && c <= (char) 0x318E);
}
public static void main(String[] args)
{
System.out.println('가' < '각');
String str = "자바클루는 JavaClue다. ㄱ은 한글이다.";
char c;
for (int i = 0; i < str.length(); i++)
{
c = str.charAt(i);
System.out.println("'" + c + "': " + isHangul(c));
}
}
}
출처 http://www.okjsp.pe.kr/bbs?act=VIEW&seq=33317&bbs=bbs4&keyfield=content&keyword=&pg=7