您的位置:首页 > 其它

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

2014-02-16 16:17 169 查看
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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: