
I needed to pull out the first sequence of numbers after the "work place name". I was able to use CacheRepository for this quite easily. I created an entity with the same name as the text file. Then it was just a matter of parsing a string (line) to get out the data I wanted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ActiveEmployer | |
{ | |
public ActiveEmployer(string line) | |
{ | |
this.Line = line; | |
if (line.Contains("==")) return; | |
var match = new Regex(@" \d\d\d\d\d? ").Match(line); | |
this.Identification = match.Value.Trim(); | |
} | |
public string Identification { get; set; } | |
public string Line { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var configBuilder = new FileRepositoryConfigBuilder(".") | |
.WithFileExtension(".txt") | |
.Build(); | |
using (var fileRepository = configBuilder.BuildRepository()) | |
{ | |
var activeEmployers = fileRepository.GetAll<ActiveEmployer>(); | |
foreach (var activeEmployer in activeEmployers) | |
{ | |
if (activeEmployer.Identification == null) continue; | |
// Do some stuff with the activeEmployer.Identification | |
} | |
} |
No comments:
Post a Comment