日期:2014-05-18  浏览次数:20792 次

怎么判断文本中的年月日,是数组的第几个值?
年 月 日
有个string.Array 类型:dd=["12 3 17" "09 12 12" "12 12 3" "11 9 3" "12 3 18"];
有下列文本内容:怎么判断文本中的年月日,是数组的第几个值?
  年 月 日  
 1 12 3 17 22 0 0.0
  1.500000000000D+01
 2 12 3 18 4 0 0.0
  6.500000000000D+01
13 12 3 18 12 0 0.0
  4.300000000000D+01
 4 09 12 12 4 0 0.0
  7.400000000000D+01
 5 12 12 3 6 0 0.0
  2.600000000000D+01
 6 12 3 18 11 59 44.0
  0.000000000000D+00
37 12 3 18 2 0 0.0
  4.700000000000D+01
28 12 3 18 4 0 0.0
  4.900000000000D+01
 9 11 9 3 10 0 0.0
  3.600000000000D+01
10 12 3 18 4 0 0.0
  7.200000000000D+01
11 12 3 17 22 0 0.0
  5.700000000000D+01
12 12 3 18 10 0 0.0
  8.000000000000D+01
33 12 3 18 12 0 0.0
  3.200000000000D+01
14 12 3 18 12 0 0.0
  6.300000000000D+01
45 12 3 18 8 0 0.0
  4.300000000000D+01
16 12 3 18 11 59 44.0
  5.000000000000D+00
17 12 3 18 0 0 0.0


------解决方案--------------------
C# code

           string[] dd = new string[] { "12 3 17", "09 12 12", "12 12 3", "11 9 3", "12 3 18" };
            string[] txtdata = File.ReadAllLines(@"C:\1.txt", System.Text.Encoding.GetEncoding("GB2312"));
            Dictionary<string, int> listdic= new Dictionary<string, int>();
            foreach (string s in txtdata)
            {
                foreach (Match m in Regex.Matches(s, @"\d+ (\d{2} \d{1,2} \d{1,2})"))
                {
                    for (int k = 0; k < dd.Length; k++)
                    {
                        int i = 0;
                        if (m.Groups[1].Value.Equals(dd[k]))
                        {
                            i = k;
                            listdic.Add(s, i);//结果
                        }
                    }
                }

            }

------解决方案--------------------
都是些高手呀,