posts - 325,  comments - 25,  trackbacks - 0

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("<", "&lt;");
  changeStr = changeStr.replaceAll(">", "&gt;");
  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 长春语林科技 阅读(554) 评论(0)  编辑  收藏 所属分类: util

只有注册用户登录后才能发表评论。


网站导航:
 
<2009年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

 

长春语林科技欢迎您!

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜