-1

This is a sample of the textdelimited file

"11- 4-2014","20:54:22","","3974","1","1","1"
"11- 4-2014","20:55:25","","1411","1","1","1"
"11- 4-2014","20:55:26","","3177","1","1","1"
"11- 4-2014","20:55:32","","4051","1","1","1"

I need it to parse and write to a text file looking like

ID         DateTime                 Area       Numb1          Num2            Num3    

1     11/4/2014-20:47:48       4297            1                  1                    1
2     11/4/2014-20:52:03       4013            1                  1                    1

The validation part comes in to check if 'Area' actually has 4 numbers, if it doesn't, Write all errors to a separate text file in the same format.

noobnoh
  • 17
  • 2
  • 2
    Possible duplicate of [Parsing CSV files in C#](http://stackoverflow.com/questions/2081418/parsing-csv-files-in-c-sharp) – Kevin Rak Mar 04 '16 at 18:40
  • I was able to parse the text file to what i wanted to look like but it was the validating part that I actually need help with. I'm not too sure where to start – noobnoh Mar 04 '16 at 18:46

1 Answers1

1

Check out this answer:

https://stackoverflow.com/a/20523165/4875896

quote: Add a reference to Microsoft.VisualBasic.dll (works fine in C#, don't mind the name)

using (TextFieldParser parser = new TextFieldParser(@"c:\temp\test.csv"))
{
 parser.TextFieldType = FieldType.Delimited;
    parser.SetDelimiters(",");
    while (!parser.EndOfData)
    {
        //Process row
        string[] fields = parser.ReadFields();
        foreach (string field in fields)
        {
            //TODO: Validate field and save as needed.
        }
    }
}
Community
  • 1
  • 1
Kevin Rak
  • 336
  • 2
  • 14
  • 3
    Instead of copy-paste of existing answer please suggest/comment as duplicate. There is very low value in doing so (at least you've provided source link - so post does not need "plagiarized content" flags, just no votes/low quality). – Alexei Levenkov Mar 04 '16 at 18:39
  • Thanks for the tip! I'll do that in the future. – Kevin Rak Mar 04 '16 at 18:40