Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
I get that English may be a second language but not clear. "which means single empty cell of a perticular row should be considered" –  Blam Jun 18 at 13:39
    
Is it column or row you want to eliminate? –  LIUFA Jun 18 at 13:42
    
I want to eliminate or ignore complete column –  Sheridan Jun 18 at 13:46
    
I want to eliminate "column". –  Ujjwal Jun 18 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 –  Ujjwal Jun 18 at 13:49

1 Answer 1

up vote 1 down vote accepted

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();
}
share|improve this answer
    
any suggestions on doing it effectively? –  Ujjwal Jun 18 at 14:13
    
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. –  Sheridan Jun 18 at 14:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.