我晕!这是java吗?
是的话,根据字节读不就可以吗!
1.把他节成三部分,<!---### 一部分str1
  ... 一部分str2
  ###---> 一部分 str3
2 把要替换的内容替换str2
3 把str1 str2 str3 连接起来
我就知道这些,不知道可以否?

解决方案 »

  1.   

    用String的indexof方法,分别得到 <!---### 和 ###---> 的index,然后把中间的字符串替换掉,循环操作就可以了
    就是indexof和substring两个方法
    不知道有没有什么更好的方法,replace()?
      

  2.   

    String a= new String(" <!--###TFTPFILE###--> on host <!--###TFTPADDRESS###-->? [confirm]");
    String replace = new String("asdfasdf");
    a=a.replaceAll("<!--###.+?###-->","<!--###"+replace+"###-->");仅是替换
      

  3.   

    谢谢...现在有一个问题.
    当<!---### ... ###--->不止一个的时候  ...  里面的内容也不相同.所要替换的内容也不同.
    针对这种情况.应该如何处理呀~!?
      

  4.   

    String prefix = "<!--###";
            String suffix = "###-->";
            String result = "";
            String original = "";
            String replacement = "HelloWorld!";
            Pattern p = Pattern.compile(prefix + ".*?" + suffix);
            Matcher m = p.matcher("recv $data3 3 \"Write file <!--###TFTPFILE###--> on host <!--###TFTPADDRESS###-->? [confirm]\" next error1");
            while (m.find()) {
                result = m.group();
                original = result;
                original = original.substring(prefix.length());
                original = original.substring(0, original.length() - suffix.length());
                // replacement = getReplacement(original);
                result = result.replaceAll(original, replacement);
            }
            System.out.println(result + '\n' + original);自己写一个 getReplacement 获得相应替代
      

  5.   

    http://www-900.ibm.com/developerWorks/cn/java/j-mer0827/index.shtml
      

  6.   

    package tips;
    import java.util.regex.*;
    /**
     * @author Administrator
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    public class MatcherPatter {
    public static void main(String[] args) {
    String prefix = "<!--###";
    String suffix = "###-->";
    Pattern p = Pattern.compile(prefix + "\\w*" +suffix);  //<!--###\\p{Upper}###-->
    Matcher m = p.matcher("xvb<!--###BFSSGD###--> ad@<!--###Bd45GD###--> [email protected]");
    while(m.find()) {
    System.out.println(m.group().substring(prefix.length(), 
    m.group().length()-suffix.length()));
    }
    String s = m.replaceAll(prefix + "12345" + suffix);
    System.out.println(s);
    }
    }
      

  7.   

    String prefix = "<!--###";
    String suffix = "###-->";
    Pattern p = Pattern.compile(prefix + "\\w?" +suffix);  
    Matcher m = p.matcher("xvb<!--###r###--> ad@<!--###Bd45GD###--> [email protected]");
    StringBuffer sb = new StringBuffer();
        while(m.find()) {
         m.appendReplacement(sb,prefix + "12345" + suffix);     
        }
         m.appendTail(sb);
         System.out.println(sb.toString());