using System; using System.Linq; public class Test { public static void Main() { Console.WriteLine(ReplaceEveryNInEveryWord("1234567 12345\n1234", 3, '#', " \n;")); Console.ReadLine(); } private static string ReplaceEveryNInEveryWord (string inputString, short n, char replaceToWhat, string separators) { char[] temp = inputString.ToArray(); byte countToN = new byte(); for (int i = 0; i < temp.Length; i++) { countToN++; if (separators.Contains(temp[i])) countToN = 0; else if (countToN % n == 0) temp[i] = replaceToWhat; } return new string(temp); } }