就是有一个字符串
如:just a test只是测试一下.如果我用str.substring(0,13)得到的结果是:just a test只是我的问题是:
一个中文有二位.所以我想得到的结果是:just a test只也就是说给一个起点,终点.然后中文按二位来算.拿里面的一段字符串出来.
怎么做呢?能写一下给我吗?解决马上给分.谢谢~~!

解决方案 »

  1.   

    public static String getLimitLengthString(int len, String symbol) throws UnsupportedEncodingException {
         int counterOfDoubleByte = 0;
         byte b[] = symbol.getBytes("gb2312");
         if(b.length <= len)
           return "";
         for(int i = 0; i < len; i++){
           if(b.length < 0)
             counterOfDoubleByte++;
         }     if(counterOfDoubleByte % 2 == 0)
           return new String(b, 0, len, "gb2312");
         else
           return new String(b, 0, len - 1, "gb2312");
       }
      

  2.   

    java默认的中文在substring中为1,所以要答到楼主的要求只能先重新定义str.length