JAVA & Open Framework2012. 8. 6. 14:40

<%@ page contentType="text/html;charset=euc-kr" %>
<%
    String title = "大韓民國에는 1km마다 맛있는 맛집들이 많이 있습니다!!!";
    title = cutStr(title,17);
    out.println(title);
%>
<%!
    public static String cutStr(String str,int cutByte)
    {
      byte [] strByte = str.getBytes();
      if( strByte.
length < cutByte )
        return str;
      int cnt = 0;
      for( int i = 0; i < cutByte; i++ )
      {
         if( strByte[i] < 0 )
         cnt++;
      }

     String r_str;
     if(cnt%2==0) r_str = new String(strByte, 0, cutByte );
     else r_str = new String(strByte, 0, cutByte + 1 );

     return r_str;
    }
%>

Posted by 아로나