try:<%
 String sTs = "。ABCDE%" ;
 int index ;
 String re = "A" ;
 String pre = "a" ;
 if ((index=sTs.indexOf(re))!=-1)
out.print(sTs.substring(0,index)+pre+sTs.substring(index+re.length())) ;     re = "E%" ;
 pre = "hh" ;
 if ((index=sTs.indexOf(re))!=-1)
out.print(sTs.substring(0,index)+pre+sTs.substring(index+re.length())) ;%>

解决方案 »

  1.   

    非常规方法,但更方便有效
    public string eliminateStr(String srcString,String token){
    try{
    StringTokenizer st=new StringTokenizer(srcString,token);
    String rstString="";
    while(st.hasMoreTokens())
    rstString+=st.nextToken();
    }catch(Exception e){}
    return (str.equals(""))?srcString:rstString
    }
      

  2.   

    一、    /**
         * Replaces one string with another throughout a source string.
         *
         * @param in the source String
         * @param from the sub String to replace
         * @param to the sub String to replace with
         * @return a new String with all occurences of from replaced by to
         */
        public static String replaceInString(String in, String from, String to) {
            if (in == null || from == null || to == null) {
                return in;
            }        StringBuffer newValue = new StringBuffer();
            char[] inChars = in.toCharArray();
            int inLen = inChars.length;
            char[] fromChars = from.toCharArray();
            int fromLen = fromChars.length;        for (int i = 0; i < inLen; i++) {
                if (inChars[i] == fromChars[0] && (i + fromLen) <= inLen) {
                    boolean isEqual = true;
                    for (int j = 1; j < fromLen; j++) {
                        if (inChars[i + j] != fromChars[j]) {
                            isEqual = false;
                            break;
                        }
                    }
                    if (isEqual) {
                        newValue.append(to);
                        i += fromLen - 1;
                    }
                    else {
                        newValue.append(inChars[i]);
                    }
                }
                else {
                    newValue.append(inChars[i]);
                }
            }
            return newValue.toString();
        }
      

  3.   


    public static String replace(String str,String oldstr,String newstr){
    String ret = str;
    int strlen1 = oldstr.length();
    while(ret.indexOf(oldstr)!=-1){
    int strlen = ret.length();
    int index = ret.indexOf(oldstr);
    ret = ret.substring(0,index) + newstr + ret.substring(index+strlen1,strlen);
    }
    return ret;
    }
      

  4.   


        /**
         * Replaces one string with another throughout a source string.
         *
         * @param in the source String
         * @param from the sub String to replace
         * @param to the sub String to replace with
         * @return a new String with all occurences of from replaced by to
         */
        public static String replaceInString(String in, String from, String to) {
            if (in == null || from == null || to == null) {
                return in;
            }        StringBuffer newValue = new StringBuffer();
            char[] inChars = in.toCharArray();
            int inLen = inChars.length;
            char[] fromChars = from.toCharArray();
            int fromLen = fromChars.length;        for (int i = 0; i < inLen; i++) {
                if (inChars[i] == fromChars[0] && (i + fromLen) <= inLen) {
                    boolean isEqual = true;
                    for (int j = 1; j < fromLen; j++) {
                        if (inChars[i + j] != fromChars[j]) {
                            isEqual = false;
                            break;
                        }
                    }
                    if (isEqual) {
                        newValue.append(to);
                        i += fromLen - 1;
                    }
                    else {
                        newValue.append(inChars[i]);
                    }
                }
                else {
                    newValue.append(inChars[i]);
                }
            }
            return newValue.toString();
        }
      

  5.   

    怎么不行呀?
    -建议做字符比对时用ASCII
      

  6.   

    字符的过滤应该放前面进行判断,你倒js去发吧,应该有答案。
    相应前台的onKeypress事件时进行判断