How to find dynamic Column name which contain string?

Hello,

Can anyone please help me on this below issue

image

In my Excel i have three column i need to find the column name which contain string “YES”
String “YES” will be dynamic it can be in any column.
If the string “YES” is present in column “Single” BOT should give the column Name as “Single” as Output.

dtOutput.Columns.Contains(“yes”)`

or

(From col in dt.columns.cast(of system.data.datacolumn) select Convert.ToString(col.columnName).Trim).Toarray(). Contains (“Yes”)

a classical modelling could look like this:

String.Format("RowIndex: {0} - ColumnName: {1} ", ridx.toString, dtData.columns(cidx).ColumnName)

We also can do it with LINQ
arrColNames =

(From d In dtData.AsEnumerable()
Let cns = d.ItemArray.Select(Function (x, i) dtData.Columns(i).ColumnName ).Where(Function (c) d(c).toString.ToUpper.Contains("YES"))
Select x = cns).SelectMany(Function (x) x).Distinct().toArray

it will report all columnnames where in any row the contained YES was found

Find starter help here:
GetRIX-CIX-ColName_AnyColContainsValue.xaml (10.9 KB)

1 Like

Thank you so much Peter

Thank you veera Raj

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.