import java.io.BufferedReader;
import java.io.Reader;
import java.sql.Clob;
public class StringUtil {
public static boolean validateNull(String args) {
if (args == null || args.length() == 0) {
return true;
} else {
return false;
}
}
public static String chanageNull(String source, String target) {
if (source == null || source.length() == 0 || source.equalsIgnoreCase("null")) {
return target;
} else {
return source;
}
}
public static String HTMLChange(String source) {
String changeStr = "";
changeStr = source.replaceAll("&", "&");
changeStr = changeStr.replaceAll(" ", " ");
changeStr = changeStr.replaceAll("<", "<");
changeStr = changeStr.replaceAll(">", ">");
changeStr = changeStr.replaceAll("\r\n", "<br>");
return changeStr;
}
public static String clobToString(Clob c) {
String content = new String();
Clob clob = c;
try {
if (clob != null) {
Reader is = clob.getCharacterStream();
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
while (s != null) {
content += s;
s = br.readLine();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return content;
}
public static String cutEucStr(String _str, int len) {
String retStr = "";
_str = _str.trim();
try {
if (_str != null && !"".equals(_str)) {
if (_str.length() > len) {
String temp = _str.substring(0, len);
int blank_index = temp.lastIndexOf(" ");
if (blank_index > 0) {
retStr = _str.substring(0, blank_index) + "...";
} else {
retStr = temp + "...";
}
} else {
retStr = _str;
}
}
} catch (Exception ex) {
retStr = "";
}
return retStr;
}
public static String getMaxNumber(String number) {
if (number.length() == 1)
number = "00" + number;
if (number.length() == 2)
number = "0" + number;
return number;
}
public static String printXing(int m) {
String blank = "*";
StringBuffer sb = new StringBuffer();
for (int i = 1; i <= m; i++) {
sb.append(blank);
}
return sb.toString();
}
public static String toHtml(String str)
{
StringBuffer strBuffer = new StringBuffer();
for(int i=0; i<str.length();i++) {
if(str.charAt(i)=='\n'){
strBuffer.append("<br/>");
}
else{
strBuffer.append(str.charAt(i));
}
}
return strBuffer.toString();
}
}
posted on 2009-04-06 14:33
长春语林科技 阅读(555)
评论(0) 编辑 收藏 所属分类:
util