fork(3) download
  1. using System;
  2. using System.Globalization;
  3. using System.Text;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var accentedEs = "e\u0301e\u0301e\u0301";
  10. var fourCircles = char.ConvertFromUtf32(0x1F01C);
  11. var normalString = "hello";
  12. var normalStringWithRepeatingChar = "hellooo";
  13. var twelveCircles = fourCircles + fourCircles + fourCircles;
  14.  
  15. Console.WriteLine(HasConsecutiveChars(normalString, 3));
  16. Console.WriteLine(HasConsecutiveChars(twelveCircles, 3));
  17. Console.WriteLine(HasConsecutiveChars(accentedEs, 3));
  18. Console.WriteLine(HasConsecutiveChars(normalStringWithRepeatingChar, 3));
  19. }
  20.  
  21. public static bool HasConsecutiveChars(string source, int sequenceLength)
  22. {
  23. var charEnumerator = StringInfo.GetTextElementEnumerator(source);
  24. var currentElement = string.Empty;
  25. int count = 1;
  26. while (charEnumerator.MoveNext())
  27. {
  28. if (currentElement == charEnumerator.GetTextElement())
  29. {
  30. if (++count >= sequenceLength)
  31. {
  32. return true;
  33. }
  34. }
  35. else
  36. {
  37. count = 1;
  38. currentElement = charEnumerator.GetTextElement();
  39. }
  40. }
  41. return false;
  42. }
  43. }
Success #stdin #stdout 0.04s 23968KB
stdin
Standard input is empty
stdout
False
True
True
True