c# - Get largest column name that come before a given column name in a list of Excel columns string -
please consider lists:
var list1 = {}; var list2 = {"a"}; var list3 = {"ae"}; var list4 = {"a", "b", "f", "h", "aa", "ac", "ae"};
this lists excel columns. want find column name come before given column name, example if want find column come before "n" want results lists:
null // list 1 "a" // list 2 null // list 3 "h" // list 4
how can write linq query returns result me?
thanks
assuming list ordered, 1 possible way :
yourlist.takewhile(o => exceltonumber(o) < exceltonumber("n")) .lastordefault();
exceltonumber()
method convert excel column name integer, mentioned in this post. included method definition below easy reference, credit 100% contributors of linked post :
int exceltonumber(string x) { return x.aggregate(0, (s, c) => s * 26 + c - 'a' + 1); }
Comments
Post a Comment