This solution provided in this link was really helpful:
DataColumn[] columns = tbl.Columns.Cast<DataColumn>().ToArray();
bool anyFieldContainsPepsi = tbl.AsEnumerable()
.Any(row => columns.Any(col => row[col].ToString() == "PEPSI"));
- But I need to return, instead of bool, the index of the "found" value. Should I try this idea? Note that I do need the Line Number/Index and the Column Number/Index.
My code at this point:
bool find = csvDataOnlyHeader.Rows.Cast<DataRow>().Any(r => r.ItemArray.Any(c => c.ToString().Contains("SN:")));
DataColumn[] columns = csvDataOnlyHeader.Columns.Cast<DataColumn>().ToArray();
bool anyFieldContains = csvDataOnlyHeader.AsEnumerable()
.Any(row => columns.Any(col => row[col].ToString() == "SN:"));
What do I need:
- Search the whole DataTable for a specific string (not caring about columns name or position).
- Return the Index (or Indexes) of the places that contains this string. (I.e. line 2 column 4)