0
点赞
收藏
分享

微信扫一扫

截取字符串,只截取前N个字节的字符


   public  void cutString(String str, int n)
  {
      String temp;
       int count=0;
       for ( int i = 0; i < str.length(); i++) {
        temp=str.charAt(i)+"";
        count+=temp.getBytes().length;
         if(count>n)
             break;
        System.out.print(temp);
    }
  }
  @Test
   public  void testString()
  {
      cutString("我ABC好的sfd", 7);
  }
————————————————

举报

相关推荐

0 条评论