2010年4月20日 星期二

String 如何過濾String中的某些文字將其移除

example call eregi_replace("\r\n | \r | \n | \n\r", "", strResult);

public String eregi_replace(String strFrom, String strTo, String strTarget)
{
    String strPattern = "(?i)" + strFrom;
    Pattern p = Pattern.compile(strPattern);
    Matcher m = p.matcher(strTarget);
    if(m.find())
   {
       return strTarget.replaceAll(strFrom, strTo);
   }
   else
   {
       return strTarget;
   }
}

沒有留言:

張貼留言