从textarea中获得的 文本 要
经过这样处理之后 存储
才可以确保读出数据 可以保持 原有格式?
比如 分行显示

解决方案 »

  1.   

    //定义一个类CodeFilter
    public class CodeFilter{
    public CodeFilter(){
    }
    //特殊字符转为Html
    public static String toHtml(String s){
    if(s == null){
    s = "";
    return s;
    }
    s = Replace(s.trim(),"&","&");
            s = Replace(s.trim(),"<","&lt;");
    s = Replace(s.trim(),">","&gt;");
    s = Replace(s.trim(),"\t","    ");
    s = Replace(s.trim(),"\r\n","\n");
    s = Replace(s.trim(),"\n","<br>");
    s = Replace(s.trim(),"  "," &nbsp;");
    s = Replace(s.trim(),"'","&#39;");
    s = Replace(s.trim(),"\\","&#92;");
    return s;
        }
    //逆
        public static String unHtml(String s){
    s = Replace(s,"<br>","\n");
    s = Replace(s,"&nbsp;"," ");
    return s;
       }
        public static String filString(int c,String s){
    String a = s.substring(0,c);
    return a;
       }
        public static String strByteCopy(String str,int nEnd)
    {
    if(nEnd==0)
    return "";
    byte[] byteStr=str.getBytes();
    int k=byteStr.length;
    String strSub=new String(byteStr,0,nEnd<k?nEnd:k);
    if (strSub.length()==0) strSub=new String(byteStr,0,nEnd-1);
    if (nEnd<k) strSub = strSub + "..";
    return strSub;
    }
     }
      

  2.   

    Replace 函数我找了一个 不能用呢??谁能给一个?