private long getStringByteLength(String str,int maxlength){
if(str==null)
return 0;
int tmp_len = maxlength;
if(str.length()<maxlength)
tmp_len = str.length();
else if(str.length()>maxlength*2)
tmp_len = maxlength*2;
char[] tempchar = str.substring(0, tmp_len).toCharArray();
int intVariable = 0;
String s1 = null;
for(int i=0;i<tempchar.length && intVariable<=maxlength;i++){
s1 = String.valueOf(tempchar[i]);
intVariable += s1.getBytes().length;
}
s1= null;
tempchar = null;
return intVariable;
}
public String updateTxt(String txt, int num) {
if (txt == null)
return "";
int initVariable = 0;
StringBuffer restr = new StringBuffer();
if (getStringByteLength(txt,num) <= num)
return txt;
String s1=null;
byte[] b;
char[] tempchar = txt.toCharArray();
for (int i = 0; (i < tempchar.length && num > initVariable); i++) {
s1 = String.valueOf(tempchar[i]);
b = s1.getBytes();
initVariable += b.length;
restr.append(tempchar[i]);
}
if (num == initVariable || (num == initVariable - 1)) {
restr.append("...");
}
return restr.toString();
}