Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否使用regexp解析文本文件_C#_Regex_Linq - Fatal编程技术网

C# 是否使用regexp解析文本文件

C# 是否使用regexp解析文本文件,c#,regex,linq,C#,Regex,Linq,我有一个包含以下内容的文本文件: Warning 18.05.2012 16:27:45 www.site.com 0 None BusyCount: 00:00:00.0000880 Warning 18.05.2012 16:27:45 www.site.com 0 None GetBusyPlace: 00:00:00.7759916 Warning 18.05.2012 16:27:44 www.site.com 0 None GetHal

我有一个包含以下内容的文本文件:

Warning 18.05.2012 16:27:45 www.site.com    0   None    BusyCount: 00:00:00.0000880
Warning 18.05.2012 16:27:45 www.site.com    0   None    GetBusyPlace: 00:00:00.7759916
Warning 18.05.2012 16:27:44 www.site.com    0   None    GetHallPlan: 00:00:00.0098537
Warning 18.05.2012 16:27:44 www.site.com    0   None    GetSeatPrice: 00:00:00.1462649
Warning 18.05.2012 16:27:40 www.site.com    0   None    BusyCount: 00:00:00.0000988
Warning 18.05.2012 16:27:40 www.site.com    0   None    GetBusyPlace: 00:00:00.7330764
Warning 18.05.2012 16:27:39 www.site.com    0   None    GetHallPlan: 00:00:00.0435432
我有三个数组:

List<string> getSeatPrice = new List<string>();
List<string> getBusyCounts = new List<string>();
List<string> getHallPlan = new List<string>();
List getSeatPrice=new List();
List getBusyCounts=新列表();
List getHallPlan=新列表();
如何解析此文本文件并从字符串中获取时间,例如
GetBusyPlace:00:00:00.7759916
,并将其放入适当的数组中


谢谢

看起来像是固定宽度的字段格式

我建议使用
Microsoft.VisualBasic.FileIO
命名空间中的类(只需添加对
Microsoft.VisualBasic.dll
的引用,就可以了)


这是一个.NET库,您可以设置它来指定字段宽度和类型,以便获得字段的强类型视图。

看起来文件中的每一行都是以空格分隔的标记集。在这种情况下,最简单的方法是使用
String.Split()
,并根据标记在字符串中的位置获取所需的标记

var getSeatPrice = new List<string>();
var getBusyCounts = new List<string>();
var getHallPlan = new List<string>();
foreach (var line in File.ReadAllLines("c:\\data\\myfile.txt")) {
    var tokens = line.Split('\t', ' ');
    var kind = tokens[6];
    var value = tokens[7];
    switch (kind) {
        case "GetSeatPrice:":
            getSeatPrice.Add(value);
        break;
        case "BusyCount:":
            getBusyCounts.Add(value);
        break;
        case "getHallPlan:":
            getHallPlan.Add(value);
        break;
    }
}
var getSeatPrice=newlist();
var getBusyCounts=新列表();
var getHallPlan=新列表();
foreach(File.ReadAllLines(“c:\\data\\myfile.txt”)中的var行){
var tokens=line.Split('\t','');
var kind=代币[6];
var值=代币[7];
开关(种类){
案例“GetSeatPrice:”:
getSeatPrice.Add(值);
打破
案例“BusyCount:”:
getBusyCounts.Add(值);
打破
案例“getHallPlan:”:
getHallPlan.Add(值);
打破
}
}

您尝试了什么?什么是列分隔符?