본문 바로가기

IT Data/#Java

java 초성검색 메소드


# 입력된 한글 초성 추출 하기 메소드

: 초성검색해서 얻은 자료를 토대로 바로 사용 가능한 메소드로 수정했습니다.

 /** 사용자명(LOGIN_NM)을 검색명(SEARCH_NM)으로 변경하여 반환한다. */

    private String convertName( String name ){

    String rtName = "";

    char epName;

    try{

    for (int i=0; i<name.length(); i++){

    epName = name.charAt(i);

    rtName = rtName + Direct(epName);

    }

    //System.out.println("[convertName(SearchName)]rtName["+rtName+"]");

   

    }catch (Exception e) {

CommonUtil.print(e, "convertName err: UserBean.convetName(str)");

}

   

    return rtName;

    }

    public String Direct(char b){

           String chosung = null;

           int first = (b - 44032 ) / ( 21 * 28 );

            switch(first){

                case 0:

                chosung="ㄱ";

                    break;

                case 1:

                    chosung="ㄲ";

                    break;

                case 2:

                    chosung="ㄴ";

                    break;

                case 3:

                chosung="ㄷ";

                    break;

                case 4:

                    chosung="ㄸ";

                    break;

                case 5:

                    chosung="ㄹ";

                    break;

                case 6:

                    chosung="ㅁ";

                    break;

                case 7:

                chosung="ㅂ";

                break;

                case 8:

                    chosung="ㅃ";

                    break;

                case 9:

                chosung="ㅅ";

                    break;

                case 10:

                    chosung="ㅆ";

                    break;

                case 11:

                    chosung="ㅇ";

                    break;

                case 12:

                chosung="ㅈ";

                    break;

                case 13:

                    chosung="ㅉ";

                    break;

                case 14:

                    chosung="ㅊ";

                    break;

                case 15:

                    chosung="ㅋ";

                    break;

                case 16:

                    chosung="ㅌ";

                    break;

                case 17:

                    chosung="ㅍ";

                    break;

                case 18:

                    chosung="ㅎ";

                    break;

                default: chosung=String.valueOf(b);

            }     

        

         return chosung;

    }

활용예

convertName("네온스토리");

 = ㄴㅇㅅㅌㄹ