现在我有strArray数组,保存的是文本中的每一行,即strArray[0]代表文本第一行,现在希望能够写一个for语句,要求就是把这个文本中/*与*/之间的语句行数数出来,应该如何写呢?急

解决方案 »

  1.   

    int lines = 0;
    bool sign = false;
    for(int i=0;i<strArray.Length;i++)
    {
      string str = strArray[i];
      if(str.StartsWith("/*"))
        sign = true;
      if(sign)
        lines++;
      if(str.EndsWith("*/"))
        break;
    }
      

  2.   

    用正则表达式。。
    Regex reg=new Regex(@"/\*(.*?)/\*");
      

  3.   

    private void button1_Click(object sender, EventArgs e)
            {
                
                string FILE_NAME = @"d:\vs2005\A.txt";
                if (!File.Exists(FILE_NAME))
                {
                    Console.WriteLine("{0} does not exist.", FILE_NAME);
                    return;
                }
                string[] str = File.ReadAllLines(FILE_NAME);            int t = 0;
                bool bln = false;
                for (int x = 0; x < str.Length; x++)
                {
                    if (str[x].StartsWith("/*"))  bln = true;
                    if (bln)  t++;              
                    if (str[x].EndsWith("*/"))  bln = false;
               }
                System.Console.WriteLine((t - 2).ToString());
            }
      

  4.   

    a.txt內容為
    /*
    A
    B
    C
    Ddfasdf
    sfas
    sfas
    sdf
    E
    F
    */
    DDD
    S
    D
    D
    D
      

  5.   

    StartsWith不太好吧,如果人家是int aaa; /* dsafsdf*/就失效了