Package com.sec.util;
/**
* String Tool class
* @author Administrator
*
*/
public class Stringutil {
/**
* Methods for filtering <,>,\n strings
* @param input
* @return
*/
public static string filterhtml (string input) {
if (input = = NULL | | input.length () = = 0) {
return input;
}
input = Input.replaceall ("&", "&")
. ReplaceAll ("<", "LT;")
. ReplaceAll (">", ">")
. ReplaceAll ("", " ")
. ReplaceAll (",", "& #39;")
. ReplaceAll ("\" "," " ")
. ReplaceAll ("\ n", "<br>");
return input;
}
/**
* Verify that the string is empty (null or empty string)
* @param str to validate the string
* @return validation result (Null string returns True, otherwise false)
*/
public static Boolean isnullorempty (String str) {
if (str = = NULL | | "". Equals (Str.trim ())) {
return true;
}
return false;
}
/**
* Omit the string part character by the specified length
* @param str string
* @param len preserves the length of the string
* @return The omitted string
*/
public static string Omitstring (String Str,int len) {
StringBuffer sb=new StringBuffer ();
if (ByteLength (str) >len) {
int count=0;
for (int i = 0; i < str.length (); i++) {
Char Temp=str.charat (i);
if (integer.tohexstring (temp). Length () ==4) {
count+=2;
}else {
count++;
}
if (count<len-3) {
Sb.append (temp);
}
if (count==len-3) {
Sb.append (temp);
Break
}
if (count>len-3) {
Sb.append ("");
Break
}
}
Sb.append ("...");
}else {
Sb.append (str);
}
return sb.tostring ();
}
public static int bytelength (String str) {
int count=0;
for (int i = 0; i < str.length (); i++) {
if (integer.tohexstring (Str.charat (i)). Length () ==4) {
count+=2;
}else {
count++;
}
}
return count;
}
}
String Tool Class (method for specifying the length of the string and whether to determine if it is empty)