用命令打开一个文本后,怎么可以保存文本中的不同日期,到一个数组中?
比如有这样的文本:文本内容最多时候达到30000条,不知道怎么写循环...
年 月 日
1 12 9 17 22 0 0.0
1.500000000000D+01
5.904180000000D+05
2 12 3 18 4 0 0.0
2.000000000000D+00
7.218000000000D+03
3 12 6 18 12 0 0.0
4.300000000000D+01
3.847200000000D+04
4 09 12 18 4 0 0.0
7.400000000000D+01
7.218000000000D+03
9 12 3 16 10 0 0.0
3.600000000000D+01
2.881800000000D+04
10 12 3 18 4 0 0.0
7.200000000000D+01
7.218000000000D+03
51 12 3 17 22 0 0.0
5.700000000000D+01
5.904180000000D+05
12 12 3 19 10 0 0.0
8.000000000000D+01
2.881800000000D+04
15 12 3 18 8 0 0.0
4.300000000000D+01
2.161800000000D+04
定义一个数组string [] ssss用来保存日期,相同的日期就不保存。数组最后应该是["12 9 17","12 3 18"...]?不知道有没有办法实现?
------解决方案--------------------
C# code
string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取tx
string pattern = @"(?i)(?<=\d+\s+)(\d+\s+){3}(?=\d+\s+0 0\.0)";
string[] ss = Regex.Matches(tempStr, pattern).Cast<Match>().Select(a => a.Value).Distinct().ToArray();
/*
[0] "12 9 17 " string
[1] "12 3 18 " string
[2] "12 6 18 " string
[3] "09 12 18 " string
[4] "12 3 16 " string
[5] "12 3 17 " string
[6] "12 3 19 " string
*/