'stringToByte'에 해당되는 글 1건

  1. 2007/10/12 String 을 Byte 단위로 자르는 함수
소켓통신이나 전문 처리를 할때  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);
    }
이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by 건빵쥔곰