Faraj1969
asked on
Find longest string in every DataTable column
Hi Experts
In this question I was able to get the length of the longest text in every column, can we modify the method to get the string itself, not the length ? To make it a little more clearer, assuming the tblData have 6 columns, the maxLenCols List should have 6 strings representing the longest string in every column.
In this question I was able to get the length of the longest text in every column, can we modify the method to get the string itself, not the length ? To make it a little more clearer, assuming the tblData have 6 columns, the maxLenCols List should have 6 strings representing the longest string in every column.
maxLenCols =
Enumerable.Range(0, tblData.Columns.Count)
.Select(col => tblData.AsEnumerable()
.Select(row => (row[col]).ToString()).OfType<string>()
.Max(val => val.Length)).ToList();
Many thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry for the simplicity of my question, but when it comes to Linq, I'm a total newbie.
Many thanks mate.