fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. List<string> myList = new List<string>()
  10. {
  11. "TNCO",
  12. "TNCB",
  13. "TNIT"
  14. };
  15. string sample = "TNSD102, WHRK301, TNIT301, YTRE234";
  16.  
  17. var entries = sample.Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
  18. var firstMatch = entries.FirstOrDefault (e => myList.Any (l => e.StartsWith(l)));
  19. if (firstMatch == null)
  20. Console.WriteLine("No match!");
  21. else
  22. Console.WriteLine(firstMatch);
  23. }
  24. }
Success #stdin #stdout 0.06s 34104KB
stdin
Standard input is empty
stdout
TNIT301