1

I am using TextFieldParser class to parse the file. I want to eliminate or ignore complete column if "entire column" is empty (which means single empty cell of a perticular row should be considered) Is this possible?

Note: as per functionality, I need to use data copied to clipboard. So can not pass direct file path to the parser.

TextFieldParser parser = new TextFieldParser(new StringReader(row));
string[] delimiters = { ",", "\t" };
parser.SetDelimiters(delimiters);
string[] columns = null;
while (!parser.EndOfData)
{
columns = parser.ReadFields();
}

Appreciate your help.

6
  • I get that English may be a second language but not clear. "which means single empty cell of a perticular row should be considered" Commented Jun 18, 2014 at 13:39
  • Is it column or row you want to eliminate? Commented Jun 18, 2014 at 13:42
  • I want to eliminate or ignore complete column Commented Jun 18, 2014 at 13:46
  • I want to eliminate "column". Commented Jun 18, 2014 at 13:47
  • @Blam; if there is intermediate empty cell; for example: row 1 data (a1, a2, a3) and row 2 data (x1, "" ,x3); here empty cell should be considered Commented Jun 18, 2014 at 13:49

1 Answer 1

2

After reading through the TextFieldParser Class page on MSDN, I see that there is nothing written there that would make me think that this class can ignore a whole column. That would be something that you would have to do manually. Furthermore, your code does not seem right because you are trying to read the fields repeatedly with the same variable:

while (!parser.EndOfData)
{
    columns = parser.ReadFields();
}
Sign up to request clarification or add additional context in comments.

2 Comments

any suggestions on doing it effectively?
Yeah... put all of your string arrays into a List<string[]> and then manually iterate through each array and copy each column value into a column in a smaller array. There are lots of different ways to do this, but in all cases, you'll have to write some procedural code as you loop through each array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.