我有一个 .txt 文件,其中包含以下格式的文本:
14:04:43 29.07.2014 Process information for JONAS-PC:
Name Pid CPU Thd Hnd Priv CPU Time Elapsed Time
Idle 0 98 8 0 0 1008:29:34.706 148:49:00.765
chrome 5020 1 14 169 136008 0:00:46.332 0:06:03.319
chrome 5960 0 10 149 335704 0:19:09.992 21:07:14.101
pslist 7564 1 2 164 3324 0:00:00.218 0:00:01.236
wininit 640 0 3 85 2528 0:00:00.078 148:48:53.839
csrss 664 0 14 1091 13240 0:03:13.675 148:48:53.823
services 696 0 6 302 10912 0:00:33.243 148:48:53.776
lsass 716 0 8 959 9176 0:01:01.979 148:48:53.698
lsm 728 0 11 189 3560 0:00:00.577 148:48:53.698
winlogon 808 0 3 121 4532 0:00:00.171 148:48:53.308
svchost 896 0 11 414 8260 0:02:41.273 148:48:47.817
svchost 988 0 13 377 9064 0:03:21.896 148:48:47.739
atiesrxx 136 0 6 132 2276 0:00:00.015 148:48:47.723
svchost 580 0 20 578 25760 0:01:23.975 148:48:47.708
svchost 800 0 28 633 177208 0:37:12.592 148:48:47.692
svchost 912 0 27 847 22020 0:00:20.638 148:48:47.692
svchost 1048 0 38 1432 52952 0:01:33.834 148:48:47.677
UMVPFSrv 1076 0 3 75 1412 0:00:00.109 148:48:47.677
MSI86DA.tmp 1244 0 4 66 2532 0:00:00.015 148:48:47.474
atieclxx 1376 0 10 140 3352 0:00:00.218 148:48:47.443
svchost 1408 0 17 532 34716 0:00:40.139 148:48:47.427
spoolsv 1672 0 12 315 9544 0:00:00.218 148:48:47.045
svchost 1744 0 18 452 32556 0:01:45.175 148:48:46.985
armsvc 1888 0 4 85 1316 0:00:00.000 148:48:46.915
我已将 Spaces 删除到一个 Space 并希望将文件拆分为在 Name Pid 下添加 evrything 等到 GridviewColumn 每一行都是 GridViewColumn 中的额外行我如何解决这个问题以将 evry 行添加到 GridViewColumn:
RegexOptions options = RegexOptions.None;
Regex regex = new Regex(@"[ ]{2,}", options);
string fs = regex.Replace(s, @" ");
var fs1 = fs.Split(' ','\n');
_GameCollection.Add(new GameData {
Name = fs1[18],
PID = fs1[19],
CPU = fs1[20],
Thd = fs1[21],
Hnd = fs1[22],
CpuTime = fs1[23],
ElapsedTime = fs1[24]
});
_GameCollection.Add(new GameData
{
});
}
public ObservableCollection<GameData> GameCollection
{ get { return _GameCollection; } }
}
public class GameData
{
public string Name { get; set; }
public string PID { get; set; }
public string CPU { get; set; }
public string Thd { get; set; }
public string Hnd { get; set; }
public string CpuTime { get; set; }
public string ElapsedTime { get; set; }
}