Village For DreamChasers....

블로그 이미지
by 건빵쥔곰
  • 13662Total hit
  • 1Today hit
  • 19Yesterday hit

소켓통신이나 전문 처리를 할때  String 을 subString 으로 자르기보다 Byte  단위로 잘라서
통신을 송/수신 하기도 한다.

다음의 함수가 유용할듯  

/**
     * String 을 BYTE 단위로 자르는 함수
     * @ author 박동규
     * @ param startIndex, length
     * @ return String 잘려진 문자열
     */
   
    public String cutStringToByte (String str, int startIndex , int length) {
       
        byte[] b1 = null;
        byte[] b2 = null;
        try{
           
            if(str == null ) {
                return "";
            }
           
            b1 = str.getBytes();
            b2 = new byte[length] ;
           
            if( length > (b1.length - startIndex) ) {
                length = b1.length - startIndex;               
            }
           
            System.arraycopy(b1,startIndex,b2,0,length);
           
        } catch (Exception e) {
            e.printStackTrace();
        }
           
        return new String(b2);
    }
크리에이티브 커먼즈 라이선스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
TRACKBACK 0 AND COMMENT 0

ARTICLE CATEGORY

분류 전체보기 (35)
Stroy Village (6)
Daily Village (9)
Idea Village (20)

RECENT TRACKBACK

CALENDAR

«   2008/08   »
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

ARCHIVE