C#文本转换为数组后如何跳过文本文件中的行?
我有一个处理文本日志文件并标记文本文件的程序 在标记文本文件之后,程序应该能够跳过新输出的前5行,其中包含 “RipXP v.20081001 发布时间:2010年12月3日星期五12:50:21 Z J:\syscrawl\registry\config\system USBStor ControlSet001\Enum\USBStor“ 有人能告诉我密码吗 代码:C#文本转换为数组后如何跳过文本文件中的行?,c#,token,skip,C#,Token,Skip,我有一个处理文本日志文件并标记文本文件的程序 在标记文本文件之后,程序应该能够跳过新输出的前5行,其中包含 “RipXP v.20081001 发布时间:2010年12月3日星期五12:50:21 Z J:\syscrawl\registry\config\system USBStor ControlSet001\Enum\USBStor“ 有人能告诉我密码吗 代码: using System; using System.Collections.Generic; using System.Lin
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
namespace Testing
{
class Program
{
static void Main(string[] args)
{
TextReader tr = new StreamReader(@"C:\Test\new.txt");
String SplitBy = "----------------------------------------";
String fullLog = tr.ReadToEnd();
String[] sections = fullLog.Split(new string[] { SplitBy }, StringSplitOptions.None);
foreach (String r in sections)
{
Console.WriteLine(r);
Console.WriteLine("============================================================");
}
}
}
}
输出的示例:
“RipXP v.20081001
发布时间:2010年12月3日星期五12:50:21 Z
J:\syscrawl\registry\config\system
USBStor
ControlSet001\Enum\USBStor
CD-ROM和Ven_SanDisk和Prod_Ultra_Backup和Rev_8.32[星期三12月1日07:39:09 2010]
序列号:2584820A2890B317和1[星期三12月1日07:39:22 2010]
FriendlyName:SanDisk Ultra备份USB设备
CD-ROM&Ven_WD&Prod_VISUAL_CD_070A&Rev_1032[周三12月1日07:31:33 2010]
序列号:575836314331304639303339和1[2010年12月3日星期五05:41:48]
FriendlyName:WD虚拟CD 070A USB设备
磁盘与虚拟磁盘与产品超级备份与版本8.32[周三12月1日07:39:09 2010]
序列号:2584820A2890B317&0[星期三12月1日07:39:19 2010]
FriendlyName:SanDisk Ultra备份USB设备
ParentIdPrefix:8&2f23e350&0
磁盘和Ven_WD和Prod_My_Passport_070A和Rev_1032[星期三12月1日07:31:33 2010]
序列号:575836314331304639303339&0[Fri Dec 3 05:41:48 2010]
FriendlyName:WD My Passport 070A USB设备
其他和Ven_WD和产品使用设备及版本1032【2010年12月1日星期三07:31:33】
序列号:575836314331304639303339和2[2010年12月3日星期五05:41:48]
============================================================
还原点信息
描述:系统检查点
类型:系统检查点
创建时间:周一11月29日16:51:52 2010
J:\syscrawl\Restore\RP1\snapshot\u REGISTRY\u MACHINE\u SYSTEM
找不到ControlSet001\Enum\USBStor
====================================================“噢,我想你想从原始版本中提取字符串 替换是这里最好的解决方案
string data = tr.ReadToEnd();
data.Replace(Environment.NewLine, " ")
.Replace("----------------------------------------", "============================================================");
Console.WriteLine(data);
重新编辑
对不起,我真的不明白这个问题。但是跳过前5行
string lines = tr.ReadToEnd().Split('\n');
StringBuilder sb = new StringBuilder();
for(int i = 5; i < lines.Length; i++) sb.AppendLine(lines[i]);
string sixthLineToEnd = sb.ToString();
string lines=tr.ReadToEnd().Split('\n');
StringBuilder sb=新的StringBuilder();
对于(inti=5;i
希望有帮助。答案是流读取器,在使用拆分方法之前,它应该开始读取不同的行位置。代码:我建议您再次阅读问题,因为程序应该跳过输出的前5行…很抱歉,我已经进行了编辑。这应该是您的解决方案程序不需要跳过新行,而是在计算程序时输出的“RipXP v.20081001于2010年12月3日星期五12:50:21启动Z:\syscrawl\registry\config\system USBStor ControlSet001\Enum\USBStor”。