读书人

如何保存下面文本中的日期到数组中并

发布时间: 2012-06-13 12:30:18 作者: rapoo

怎么保存下面文本中的日期到数组中,并判断数组中已经有这个日期就不保存,格式是固定的,
文本中有很多行,这只是其中一小部分。
年 月 日
1 12 3 17 22 0 0.0
2 12 3 18 4 0 0.0
3 12 10 19 12 59 44.0
13 12 3 18 12 0 0.0
16 12 3 18 11 59 44.0
17 02 3 18 11 59 44.0
36 02 12 18 11 59 44.0


[解决办法]
Just like this

C# code
  string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取tx                string pattern = @"(?i)(?<=\d+ +)(\d+\s+){3}";                string[] ss = Regex.Matches(tempStr, pattern).Cast<Match>().Select(a => a.Value).Distinct().ToArray();                /*                 *                    [0]    "12 3 17 "    string                                [1]    "12 3 18 "    string                                [2]    "12 10 19 "    string                                [3]    "02 3 18 "    string                                [4]    "02 12 18 "    string                 */ 

读书人网 >C#

热点推荐