한글영역 범위를 체크해서 한글여부를 판단하곤 했는데...
아래에 글을 보면.... 참 간단히 해결 되네요..
유용한 자료가 있어서 퍼왔습니다!!
public class HanTest{
public static void main(String a[]){
HanTest test = new HanTest();
System.out.println("############ TEST #################");
System.out.println("sldkflkl" + test.isHanGul("sldkflkl"));
System.out.println("가나다라" + test.isHanGul("가나다라"));
System.out.println("sldk가나" + test.isHanGul("sldk가나"));
System.out.println("가나kflkl" + test.isHanGul("가나kflkl"));
}
public HanTest(){
}
public static boolean isHanGul(String s){
if(s == null || s.equals("")) return false;
for(int i=0; i<s.length(); i++){
if( isHangulCh(s.charAt(i)) ){
return true;
}
}
return false;
}
public static boolean isHangulCh(char c){
String unicodeBlock = Character.UnicodeBlock.of(c).toString();
if (unicodeBlock.equals("HANGUL_JAMO") ||
unicodeBlock.equals("HANGUL_SYLLABLES") ||
unicodeBlock.equals("HANGUL_COMPATIBILITY_JAMO"))
return true;
else
return false;
}
}
가져온 곳 :
블로그 >인생은 도전이다.
|