Posts o[c#] Read Fixed Width CSV
Post
Cancel

o[c#] Read Fixed Width CSV

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//http://stackoverflow.com/q/162727
const string REGEX_LOT = "^(?<Field1>.{28})" +
            "(?<Field2>.{56})" +
            "(?<Field3>.{14})" +
            "(?<Field4>.{140})";

Regex reLot = new Regex(REGEX_LOT, RegexOptions.Compiled);

using (StreamReader reader = new StreamReader(@"C:\s.txt"))
{
    string line;
    while ((line = reader.ReadLine()) != null)
    {
        Match match = reLot.Match(line);
        string field4 = match.Groups["Field4"].Value;
        Console.WriteLine(field4);
    }
}

origin - http://www.pipiscrew.com/?p=6287 read-fixed-width-csv

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags