Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a csv file like this.

2;PlatesPatches;2451;1166.95410292072
2;PlatesPatches;1389.5966620306;788.205841446453
2;PlatesPatches;1320.50069541029;767.732962447844
2;PlatesPatches;1356.32823365786;754.937413073714
2;PlatesPatches;1625.0347705146;839.388038942976
2;PlatesPatches;2205.95271210014;1000.61196105702
2;PlatesPatches;2451;1056.9123783032
3;SmallPatchesmosaicpavement;2354.38108484006;977.579972183588
3;SmallPatchesmosaicpavement;2451;1000.61196105702
3;SmallPatchesmosaicpavement;2451;1064.58970792768
3;SmallPatchesmosaicpavement;1988.42837273992;946.870653685675
3;SmallPatchesmosaicpavement;1394.71488178025;780.528511821975
3;SmallPatchesmosaicpavement;1404.95132127956;770.29207232267
3;SmallPatchesmosaicpavement;2065.2016689847;913.602225312935
4;Gravel;2165.00695410292;1062.03059805285
4;Gravel;2141.97496522949;1064.58970792768
4;Gravel;2121.50208623088;1067.1488178025
4;Gravel;2106.14742698192;1067.1488178025
4;Gravel;2090.79276773296;1067.1488178025
4;Gravel;2075.43810848401;1069.70792767733
4;Gravel;2060.08344923505;1072.26703755216
4;Gravel;2039.61057023644;1074.82614742698
4;Gravel;2016.578581363;1079.94436717663
4;Gravel;1988.42837273992;1082.50347705146
4;Gravel;1955.15994436718;1085.06258692629
4;Gravel;1824.64534075104;1015.96662030598
4;Gravel;1916.77329624478;1003.17107093185
4;Gravel;1983.31015299026;1000.61196105702

with respect to first column i want to print values of 3rd and 4th column.
like when first column value is 2 until then all the values of 3rd and 4th will print?

What I have tried:

OpenFileDialog opn = new OpenFileDialog();

if (opn.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new StreamReader(opn.FileName);

List<string[]> data = new List<string[]>();

int Row = 0;

while (!sr.EndOfStream)
{
string[] Line = sr.ReadLine().Split(',');
data.Add(Line);
Row++;
Console.WriteLine(Row);
}


}
Posted
Updated 1-Dec-17 22:21pm

1 solution

This is your third question on the same subject and you still do not seem to understand the format of your data. Your string[] Line = sr.ReadLine().Split(','); is not going to work because your data uses the semi-colon (';') character as a field delimiter, not the comma. I would suggest you study Using OleDb to Import Text Files (tab, CSV, custom)[^] which will make things much simpler.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900