I have a list of 5 arbitrary user-inputted strings:
List<string> original = new List<string>() {"a", "a1", "a2", "b", "b1"} ;
For each string in the original collection, I want to get back the shortest string in the list which starts the current string:
"a" -> "a"
"a1" -> "a"
"a2" -> "a"
"b" -> "b"
"b1" -> "b"
How can I do this using LINQ?
Some more examples:
{a, ghjkjajj,hkj,bn,n} => {a, ghjkjajj,hkj,bn,n}
{ghj465,abn,abn1,hj,ui} => {ghj465,abn,abn,hj,ui}
{gh465,gh1,gh} => {gh,gh,gh}
{abcd,ab} => {ab,ab}