using System;
using System.Linq;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
List<string> myList = new List<string>()
{
"TNCO",
"TNCB",
"TNIT"
};
string sample = "TNSD102, WHRK301, TNIT301, YTRE234";
var entries = sample.Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
var firstMatch = entries.FirstOrDefault (e => myList.Any (l => e.StartsWith(l)));
if (firstMatch == null)
Console.WriteLine("No match!");
else
Console.WriteLine(firstMatch);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWM7CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CiAgICAJTGlzdDxzdHJpbmc+IG15TGlzdCA9IG5ldyBMaXN0PHN0cmluZz4oKQoJCXsKCQkJIlROQ08iLAoJCQkiVE5DQiIsCgkJCSJUTklUIgoJCX07CgkJc3RyaW5nIHNhbXBsZSA9ICJUTlNEMTAyLCBXSFJLMzAxLCBUTklUMzAxLCBZVFJFMjM0IjsKCQkKCQl2YXIgZW50cmllcyA9IHNhbXBsZS5TcGxpdChuZXcgY2hhcltdIHsnLCcsICcgJ30sIFN0cmluZ1NwbGl0T3B0aW9ucy5SZW1vdmVFbXB0eUVudHJpZXMpOwoJCXZhciBmaXJzdE1hdGNoID0gZW50cmllcy5GaXJzdE9yRGVmYXVsdCAoZSA9PiBteUxpc3QuQW55IChsID0+IGUuU3RhcnRzV2l0aChsKSkpOwoJCWlmIChmaXJzdE1hdGNoID09IG51bGwpCgkJCUNvbnNvbGUuV3JpdGVMaW5lKCJObyBtYXRjaCEiKTsKCQllbHNlCgkJCUNvbnNvbGUuV3JpdGVMaW5lKGZpcnN0TWF0Y2gpOwoJfQp9