按字节截取汉子

String s = "11测试能否按照字节截取字符串";
		String ss = "";
		byte[] c = s.getBytes();
		/*System.out.println(c);
		System.out.println(c.length);*/
		if(c.length>20){
			for(int i = 0;i<20;i++){
				String a = s.substring(i,i+1);
				if( (ss + a).getBytes().length <= 20){
					ss = ss + a ;
				}else {
					break ;
				}
			}
		}
		System.out.println(ss);

你可能感兴趣的:(按字节截取汉子)