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 S1 = string. valueof (tempchar [I]);
intvariable + = s1.getbytes (). length;
}< br> S1 = NULL;
tempchar = NULL;
return intvariable;
}< br> 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 ();
}