한글스트링을 substring() 으로 잘라내면.. 깨지는 경우
한글스트링을 substring() 으로 잘라내면.. 깨지는 경우가 있습니다.

이때 사용한 함수..


public String cutString(String str,int cutLength) {
   byte[] strByte = str.getBytes();
   boolean isOdd = false;

   cutLength += (cutLength%2);

   for(int i=0; i< strByte.length; i++) {
       isOdd &= (strByte[i] < 0);
   }

    if(isOdd) cutLength++;

   if( str.length() > cutLength ) {
       str = str.substring(0,cutLength) + ".." ;
   }

   return str;
}

by 이종화 | 2006/03/22 15:37 | JAVA | 트랙백 | 덧글(1)
트랙백 주소 : http://ingenuity.egloos.com/tb/1666605
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by seo at 2009/10/13 12:58
신입개발자 인데 미흡한 부분이 많네요 ^^
substring으로 잘랐을 경우에 한글이 깨져서 찾고 있었는데,
살포시 소스만 빌려가기 아까워, 한글자 적고 갑니다

:         :

:

비공개 덧글

< 이전페이지 다음페이지 >