比如:我要判断 test.asp中,是否含有“CSDN”这个字符?

解决方案 »

  1.   

    可以把文件逐行读成字符串,然后使用contains方法。
      

  2.   

    readLine循环,判断str.indexOf("CSDN")==-1?
      

  3.   

    用字符串读出,然后用indexOf逐行判断
      

  4.   

    读取文件内容到str里面if(str.indexOf("CSDN")>-1)
    {
       包含csdn
    }
      

  5.   

    用正则表达式。
    Pattern
    Matcher
      

  6.   

    如果字符串是唯一的,根本没有必要使用正则表达式,用它反而增加开销。
    正则表达式只在对字符串有比较复杂的匹配规则时候才有用
    在这个题目里面使用indexOf就行,根本不应该使用正则表达式
      

  7.   

    to ChDw(米):
       要考虑开销,那回到C如何?   对楼主来说,学好正则表达式肯定要比应用indexOf查找受益得多,我就是这个意思。
      

  8.   

    <code><pre>
    正则表达式查找替换方法
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    /**
     * www.urlshow.com
     */
    public abstract class 正则表达式 {
        /**
         * 
         * 功能: 查找
         * @param 数据
         * @param 正则表达式
         * @return true成功,false失败
         */
        public static boolean do查找(String 数据,String 正则表达式){
            Pattern 模板=Pattern.compile(正则表达式);
            Matcher 匹配器=模板.matcher(数据);
            return 匹配器.find();
        }
        /**
         * 
         * 功能: 替换
         * @param 数据
         * @param 正则表达式
         * @param 替换
         * @return 替换结果
         */
        public static String do替换(String 数据,String 正则表达式,String 替换){
            Pattern 模板=Pattern.compile(正则表达式);
            Matcher 匹配器=模板.matcher(数据);
            return 匹配器.replaceAll(替换);
        }
        /**
         * 功能: TODO
         * @param args 
         */
        public static void main(String[] args) {
            String 数据="google,cool,top,good";
            String 正则表达式="[o]";
            String 替换="@";
            System.out.println("数据:'"+数据+"'中包含'"+正则表达式+"'对吗?");
            System.out.println(do查找(数据,正则表达式));
            System.out.println("替换结果:'"+do替换(数据,正则表达式,替换)+"'");
        }
    }
    </pre></code>
      

  9.   

    只要使用Unicode,类,变量,都可以是中文
    而且开发出来的程序很好读,文档也好写
    多习惯习惯就好了
      

  10.   

    个人有个人的习惯吧,读其他程序的时候,程序里的临时变量很不容易理解,
    不想其他人看我的程序也这样,
    csdn不能用<pre>或<code>,看起来很不顺眼,在Eclipse好的多
      

  11.   

    多交流,多沟通
    [email protected]