截取字符串,只截取前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);
  }
原文地址:https://www.cnblogs.com/passer1991/p/2712267.html