fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. Console.WriteLine(ReplaceEveryNInEveryWord("1234567 12345\n1234", 3, '#', " \n;"));
  9. Console.ReadLine();
  10. }
  11.  
  12. private static string ReplaceEveryNInEveryWord (string inputString, short n, char replaceToWhat, string separators)
  13. {
  14. char[] temp = inputString.ToArray();
  15. byte countToN = new byte();
  16. for (int i = 0; i < temp.Length; i++)
  17. {
  18. countToN++;
  19. if (separators.Contains(temp[i])) countToN = 0;
  20. else if (countToN % n == 0) temp[i] = replaceToWhat;
  21. }
  22.  
  23. return new string(temp);
  24. }
  25. }
Success #stdin #stdout 0.05s 24048KB
stdin
Standard input is empty
stdout
12#45#7 12#45
12#4