c# regex parse file in ical format and populate object with results

前端 未结 5 1961
清酒与你
清酒与你 2021-02-11 00:12

I\'m trying to parse a file that has the following format:

BEGIN:VEVENT
CREATED:20120504T163940Z
DTEND;TZID=America/Chicago:20120504T130000
DTSTAMP:20120504T1640         


        
5条回答
  •  礼貌的吻别
    2021-02-11 00:51

    Run this with a few examples and see if it does what you want. I get the other comments about splitting or IndexOf but if you're expecting that the delimiter is either a colon or a semicolon then a regex is probably better.

    string line = "LAST-MODIFIED:20120504T163940Z";
    var p = Regex.Match(line, "(.*)?(:|;)(.*)$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline);
    Console.WriteLine(p.Groups[0].Value);
    Console.WriteLine(p.Groups[1].Value);
    Console.WriteLine(p.Groups[2].Value);
    Console.WriteLine(p.Groups[3].Value);
    

提交回复
热议问题