Dovberman
asked on
How to read columns of a tab delimited text file.
I need to read each column value of a tab delimited file.
The file is retrieved.
The column values are not returned.
What do I need to modify?
Thanks,
Source file:
Tab delimited
Date OldExchange OldSymbol NewExchange NewSymbol
20120315 OTCBB REFGD OTCBB REFG
20120315 OTCBB SRWY OTCBB SRWYD
20120309 OTCBB ALDFF AMEX AXX
20120307 OTCBB SRCPD NASDAQ SRCP
I need to get the column values of each column.
str1 = value of first column "20120315";
str2 = value of 2nd column "OTCBB";
etc.
This is what I have now:
while ((line = sr.ReadLine()) != null)
{
values = line.Split(new char[] { ',' });
values[values.Length - 1] = values[values.Length - 1].Trim(new char[] { '"' });
values[0];
//Returns values[0] as "20120315\tOTCBB\tREFGD\tO TCBB\tREFG "
values[1];
//error Index was outside the bounds of the array.
How do I return the actual column values?
The file is retrieved.
The column values are not returned.
What do I need to modify?
Thanks,
Source file:
Tab delimited
Date OldExchange OldSymbol NewExchange NewSymbol
20120315 OTCBB REFGD OTCBB REFG
20120315 OTCBB SRWY OTCBB SRWYD
20120309 OTCBB ALDFF AMEX AXX
20120307 OTCBB SRCPD NASDAQ SRCP
I need to get the column values of each column.
str1 = value of first column "20120315";
str2 = value of 2nd column "OTCBB";
etc.
This is what I have now:
while ((line = sr.ReadLine()) != null)
{
values = line.Split(new char[] { ',' });
values[values.Length - 1] = values[values.Length - 1].Trim(new char[] { '"' });
values[0];
//Returns values[0] as "20120315\tOTCBB\tREFGD\tO
values[1];
//error Index was outside the bounds of the array.
How do I return the actual column values?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If two more people come in and mention using tab instead of comma for the delimiter, does that mean I get a Yahtzee?
ASKER
The tab delimiter '\t' resolved the issue. Additional detail was also helpful.
Thanks,
Thanks,