Skip to content

Instantly share code, notes, and snippets.

@ronnieoverby
Created October 7, 2014 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronnieoverby/f49095bbbd43c8a392cf to your computer and use it in GitHub Desktop.
Save ronnieoverby/f49095bbbd43c8a392cf to your computer and use it in GitHub Desktop.
file processing with coretechs.common
string text = @"
FRONT MATTER
FRONT MATTER #2
NAME: Billy B Goode
BIRTHDATE: 5/10/1984
GENDER: Male
MIDDLE MATTER
MIDDLE MATTER #2
NAME: Martha Peppers
BIRTHDATE: 3/16/1984
GENDER: Female
NAME: Smarty McSmarty
BIRTHDATE: 10/27/2005
GENDER: Male
REAR MATTER";
// regex that matches the key
// and captures the value
var rgx = new Regex(@"^[A-Z]+\: (.)");
// get a sequence that has only lines I know will be used
var interestingLines =
from l in text.ReadLines()
where rgx.IsMatch(l)
select l;
// accumulate chunks of lines to process
interestingLines
.AccumulateUntil(x => x.StartsWith("NAME: "))
.Select (x => new
{
Name = rgx.Replace(x[0], "$1"),
BirthDate = rgx.Replace(x[1], "$1").Parse(DateTime.Parse),
Gender = rgx.Replace(x[2], "$1"),
}).Dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment