fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7.  
  8. public static void Main()
  9. {
  10. string test1 = "abcd5f";
  11. string[] substrings = { "1", "2", "3", "4", "5" };
  12. bool contains = test1.ElementAtPosContains(4, substrings);
  13.  
  14. Console.WriteLine("{0} contains one of {1} at specified index {2}: {3}"
  15. ,test1
  16. ,string.Join(",",substrings)
  17. ,4
  18. , contains);
  19. }
  20.  
  21. }
  22. public static class Extensions
  23. {
  24. public static bool ElementAtPosContains(this string inputStr, int index, string[] valuesToCheck)
  25. {
  26. if (valuesToCheck == null || valuesToCheck.Length == 0 || inputStr.Length < index)
  27. return false;
  28.  
  29. return valuesToCheck.Any(sub => string.CompareOrdinal(inputStr, index, sub, 0, sub.Length) == 0);
  30. }
  31. }
Success #stdin #stdout 0.03s 33936KB
stdin
Standard input is empty
stdout
abcd5f contains one of 1,2,3,4,5 at specified index 4: True