给两个时间。比如2004-6   2007-9  怎么求出当中的年月啊如2004-7  2004-8 2004-9 等 然后把这些时间取出来。放在哪里好呢。怎么遍历啊

解决方案 »

  1.   

    string str1 = "2004-7 2004-8 2004-9";
    string[] ary = str1.Split(' ');
    for(int i=0;i<ary.Length;i++)
    {
    DateTime myd = DateTime.Parse(ary[i].ToString() + "-1");
    年月 = myd.ToString("yyyy-MM");
    }
      

  2.   

    string str1 = "2004-7 2004-8 2004-9";
    Regex regex = new Regex("\\d{4}-[0,1]?\\d{1}");
    MatchCollection col = regex.Matches(str1);
    for(int i=0; i<col.Count; i++)
    {
    Response.Write(col[i].Value);
    }