filt.java

来自「这个也是关于图书管理系统的代码」· Java 代码 · 共 73 行

JAVA
73
字号
package com.xmspk.ebp.books;
/**
 * Created by IntelliJ IDEA.
 * User: 汪雷
 * Date: 2003-4-29
 * Time: 16:16:03
 * To change this template use Options | File Templates.
 */
public class Filt
{
        public Filt(){
        }

        public static String Encode(String source)
        //过滤非法字符
        {
                if (source==null)
                        return "";
                StringBuffer buf = new StringBuffer(source);
                char c=0;
                int i=0;
                int j=0;
                int len = source.length();
                while (j<len)
                {
                        c = source.charAt(j);
                        j++;
                         if (c=='&')
                        {
                                buf.insert(i,"&#38");
                                buf.setCharAt(i+4,';');
                                i+=5;
                        }else if (c=='\n')
                        {
                                buf.insert(i,"<br");
                                buf.setCharAt(i+3,'>');
                                i+=4;
                        }else if (c=='<')
                        {
                                buf.insert(i,"&lt");
                                buf.setCharAt(i+3,';');
                                i+=4;
                        }else if (c=='>')
                        {
                                buf.insert(i,"&gt");
                                buf.setCharAt(i+3,';');
                                i+=4;
                        }else if (c=='"')
                        {
                                buf.insert(i,"&quot");
                                buf.setCharAt(i+5,';');
                                i+=6;
                        }else
                                i++;
                }
                return buf.toString();

        }

       public String Blank(Object o)
        //空字符处理
       {
        String temp = new String();
        if (o==null){
            temp = "";
            return temp;
        }
        else
            return o.toString();
      }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?