Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How can i get the list of rows which are having X Column with value 'P' from a CSV File
using Linq


1,test1,112,124
2,test2,113,124
3,test3,132,121

How can i read rows which are having 4 column value as 124

What I have tried:

How can i get the list of rows which are having X Column with value 'P' from a CSV File
using Linq


1,test1,112,124
2,test2,113,124
3,test3,132,121

How can i read rows which are having 4 column value as 124
Posted
Updated 4-Sep-17 2:22am
Comments
Graeme_Grant 4-Sep-17 8:06am    
What code have you written so far?

1 solution

Explanation in code comments:
C#
var csvList = new List<string>
{
    "1,test1,112,124",
    "2,test2,113,124",
    "3,test3,132,121"
};

var results = csvList
    // Add a key
    .Select(x => new { csv = x, key = x.Split(new[] { ',' })[3] })
    // filter by key
    .Where(x => x.key.Equals("124"))
    // return original csv
    .Select(x => x.csv);
 
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