问题1
文本内容如下
2000-02-01
2000-02-02
2000-02-03
怎么才能一次读取两行读到
2000-02-01
2000-02-02
问题2
怎么才能从文件中
adsafdsfdsfdskjlx254924521dsafdsa5
使用一个简单的命令读出其中的9.而不用循环去读取请哪位能贴出详细的代码,谢谢!

解决方案 »

  1.   

    怎么才能一次读取两行读到 
    读取到第二个换行符就行.存在数组时吧
    怎么才能从文件中 
    adsafdsfdsfdskjlx254924521dsafdsa5 
    使用一个简单的命令读出其中的9.而不用循环去读取 
                string x = "adsafdsfdsfdskjlx254924521dsafdsa5";
                string newx = x.Substring(x.IndexOf("9"), 1);
                MessageBox.Show(newx);
      

  2.   

                string x = "adsafdsfdsfdskjlx254924521dsafdsa5";
                if (x.Contains("9"))
                {
                    string newx = x.Substring(x.IndexOf("9"), 1);
                    MessageBox.Show(newx);
                }
                else
                {
                    MessageBox.Show("不存在9");
                }
      

  3.   

    第2个
    str.Substring(str.Indexof('9'),1)
      

  4.   


    你好搞笑哦,哈哈,如果是你这个理解,那还读啥,直接str="9";就完了何必:str=str.Substring(str.Indexof('9'),1);呢
      

  5.   

    看起来你的时间格式是固定的,而且每一行只有一个日期,直接点取出每一行然后对其Convert.ToDateTime。try catch获取true or false,并将false的字符串输出或者进行你要的统计。
      

  6.   

    private void button4_Click(object sender, EventArgs e)
    {
        StreamReader r=new StreamReader(@"c:\ls1.txt")                ;
        StreamWriter w = new StreamWriter(@"c:\ls2.txt");
        w.WriteLine("行号   出错行内容");
        int i = 1;  //记录出错行号
        DateTime dt;
        for (string line = r.ReadLine(); line != null; line = r.ReadLine())
        {
            // 时分秒为0时,取前10位,否则取前19位,分格符变为":"
            if (DateTime.TryParse(line.Substring(0,10),out dt)==false) w.WriteLine(i+"    "+line);
            i++;
        }
        r.Close();
        w.Close();

      

  7.   

    验证的工作就得正则,把每行数据都做个比较;合格的把他splict到数组中,再判断天数是否正确
      

  8.   


    //Try it.
                                2000-02-02 00-00-00
                                2000-02-03 00-00-00
                                2000-02-04 00-00-00
                                2000-02-05 00-00-00
                                2000-02-06 00-00-00
                                2000-02-07 00-00-00
                                2000-02-08 00-00-00
                                2000-02-09 00-00-00
                                2000-0?-1? 00-00-00
                                2000-04-31 00-00-00
                                2000-02-12 00-00-00
                                2000-02-13 00-00-00
                                2000-02-14 00-00-00
                                2000-02-15 00-00-00
                                2000-02-16 00-00-00
                                ????-02-17 00-00-00
                                2000-??-18 00-00-00
                                2000-02-?9 00-00-00
                                2000-02-20 00-00-00
                                2000-02-21 00-00-00
                                200?-02-22 00-00-00
                                2000-02-23 00-00-00
                                2000-02-24 00-00-00
                                2000-02-25 00-00-00
                                2000-0?-26 00-00-00
                                2000-02-27 00-00-00
                                2000-02-28 00-00-00
                                2001-02-29 00-00-00";            Regex re = new Regex(@"(?:(?:(2\d{3})\-(\d{2})\-(\d{2}))|(?:([\d\?]{4})\-([\d\?]{2})\-([\d\?]{2})))( 00\-00\-00)");            MatchCollection mc = re.Matches(str);            String _y = "";
                int _m = 0, _d=0;            int i = 0;            foreach (Match m in mc)
                {
                    i++;
                    _y = m.Result("$1");
                    if (_y == "")
                    {
                        Response.Write(String.Format("第{4}行: {0}-{1}-{2} {3}<br />", m.Result("$4"), m.Result("$5"), m.Result("$6"), m.Result("$7"),i));
                    }
                    else {                    _m = Int16.Parse(m.Result("$2"));
                        _d = Int16.Parse(m.Result("$3"));
                        int _intY = Int16.Parse(_y);
                        //Int16.TryParse(m.Result("$2"), _m);                    //Int16.TryParse((int)m.Result("$3"), _d);                    //Int16.TryParse(_y,(int) _intY);                    if (_intY % 4 == 0 && _m == 2 && _m > 0 && _d > 0 && _d <= 29) continue;                    if (_intY % 4 != 0 && _m == 2 && _m > 0 && _d > 0 && _d <= 28) continue;
                        if (((_m > 0 && _m != 2 && _m <= 7 && _m % 2 == 0) || (_m > 7 && _m <= 12 && _m % 2 == 1)) && _d > 0 && _d <= 30) continue;
                        if (((_m > 0 && _m != 2 && _m <= 7 && _m % 2 == 1) || (_m > 7 && _m <= 12 && _m % 2 == 0)) && _d > 0 && _d <= 31) continue;                    Response.Write(String.Format("第{4}行: {0}-{1}-{2} {3}<br />", m.Result("$1"), m.Result("$2"), m.Result("$3"), m.Result("$7"), i));                }            }
    /*
    //Result.
    第10行: 2000-0?-1? 00-00-00
    第11行: 2000-04-31 00-00-00
    第17行: ????-02-17 00-00-00
    第18行: 2000-??-18 00-00-00
    第19行: 2000-02-?9 00-00-00
    第22行: 200?-02-22 00-00-00
    第26行: 2000-0?-26 00-00-00
    第29行: 2001-02-29 00-00-00*/
      

  9.   


    //代码中,测试数据漏了一段。用这个。
                String str = @"2000-02-01 00-00-00
                                2000-02-02 00-00-00
                                2000-02-03 00-00-00
                                2000-02-04 00-00-00
                                2000-02-05 00-00-00
                                2000-02-06 00-00-00
                                2000-02-07 00-00-00
                                2000-02-08 00-00-00
                                2000-02-09 00-00-00
                                2000-0?-1? 00-00-00
                                2000-04-31 00-00-00
                                2000-02-12 00-00-00
                                2000-02-13 00-00-00
                                2000-02-14 00-00-00
                                2000-02-15 00-00-00
                                2000-02-16 00-00-00
                                ????-02-17 00-00-00
                                2000-??-18 00-00-00
                                2000-02-?9 00-00-00
                                2000-02-20 00-00-00
                                2000-02-21 00-00-00
                                200?-02-22 00-00-00
                                2000-02-23 00-00-00
                                2000-02-24 00-00-00
                                2000-02-25 00-00-00
                                2000-0?-26 00-00-00
                                2000-02-27 00-00-00
                                2000-02-28 00-00-00
                                2001-02-29 00-00-00";
      

  10.   

       Bbbb  Mmmm  Wwwww   下次给你高分,刚才控制出错了,不好意思!!