If you can read (identify) the requested column name in the CSV file that should mean that you are already able to open a CSV file and read it in a structured fashion
*
. As rows aren't named or otherwise explicitly identified in a standard way, your "row name" implies that you want to find a row that has a specific value in a kind of "name" column. So you have to identify this "name" column like you did with the other requested column and then read through the rows and stop where the "name" column contains the requested row name.
*
: Unless you're just doing a String.Contains(columnName) ? Then you need to use an actual solution to read CSV files. Take a look at this one:
A Fast CSV Reader[
^]
Edit:
Sample code using the CSVReader-solution linked above. You need to reference the "LumenWorks.Framework.IO.dll" from that solution. My test data was that small sample table from your comment in a file named "testdata.csv":
using System.IO;
using LumenWorks.Framework.IO.Csv;
string nameColumnName = "a";
string valueColumnName = "d";
string rowName = "r";
using (CsvReader csvReader = new CsvReader(new StreamReader(@"..\..\testdata.csv"), hasHeaders: true))
{
int nameColumnIndex = csvReader.GetFieldIndex(nameColumnName);
int valueColumnIndex = csvReader.GetFieldIndex(valueColumnName);
while (csvReader.ReadNextRecord())
{
if (csvReader[nameColumnIndex] == rowName)
{
string value = csvReader[valueColumnIndex];
break;
}
}
}