这是我从别人那copy过来test的,也给你看一下吧
public class T{
public static void main(String[] a){
String s = "aa阿萨wee";
System.out.println(s.length());
System.out.println(s.substring(0,6));
byte[] bytes = s.getBytes();
String s1;
int i ;
for(i =3 ;i>=0; i--){
if(bytes[i] > 0) {
System.out.println(bytes[i]);
break;
}
}
if(i % 2 == 1)s1 =new String(bytes,0,4);
else s1 =new String(bytes,0,3);
System.out.println(s1);
}
}
public class T{
public static void main(String[] a){
String s = "aa阿萨wee";
System.out.println(s.length());
System.out.println(s.substring(0,6));
byte[] bytes = s.getBytes();
String s1;
int i ;
for(i =3 ;i>=0; i--){
if(bytes[i] > 0) {
System.out.println(bytes[i]);
break;
}
}
if(i % 2 == 1)s1 =new String(bytes,0,4);
else s1 =new String(bytes,0,3);
System.out.println(s1);
}
}
解决方案 »
- getClassInstance Line: 209 - com/opensymphony/xwork2/spring/SpringObject 请大家帮我看看
- jsp response.getWrite()和response.GetouputResponse()冲突
- web开发CMS内容管理系统中的站点管理如何实现
- jsp小项目需求和注意
- 实现Web上行式输入打勾多选和批量删除
- JSTL判断
- jQuery 显示所有信息的实例
- 获取系统默认日期
- Struts真难学呀。我晕。。。。。。
- HashMap问题
- jsp中怎样将一个页面分成两个?
- 为什么我在JSP中能得到TEXT文本中的数据,却得不到在SELECT中的数据呢?
public static String stringLengthFixed(String string,int len){
String buffer = null;
byte[] byteStr = string.getBytes();
if(byteStr.length < len){
StringBuffer sb = new StringBuffer(len - byteStr.length);
for(int i = 0; i < (len - byteStr.length)/2; i++)
sb.append("...");
buffer = string + sb.toString();
}else{
buffer = new String(byteStr,0,len);
if(buffer.length() == 0) {
buffer = new String(byteStr,0,len-1);
buffer = buffer.concat(".");
}
buffer = buffer.concat("...");
}
return buffer;
}测试通过。