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);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKCQlDb25zb2xlLldyaXRlTGluZShSZXBsYWNlRXZlcnlOSW5FdmVyeVdvcmQoIjEyMzQ1NjcgMTIzNDVcbjEyMzQiLCAzLCAnIycsICIgXG47IikpOwogICAgICAgIENvbnNvbGUuUmVhZExpbmUoKTsKCX0KCQoJICAgICAgICBwcml2YXRlIHN0YXRpYyBzdHJpbmcgUmVwbGFjZUV2ZXJ5TkluRXZlcnlXb3JkIChzdHJpbmcgaW5wdXRTdHJpbmcsIHNob3J0IG4sIGNoYXIgcmVwbGFjZVRvV2hhdCwgc3RyaW5nIHNlcGFyYXRvcnMpCiAgICAgICAgewogICAgICAgICAgICBjaGFyW10gdGVtcCA9IGlucHV0U3RyaW5nLlRvQXJyYXkoKTsKICAgICAgICAgICAgYnl0ZSBjb3VudFRvTiA9IG5ldyBieXRlKCk7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgdGVtcC5MZW5ndGg7IGkrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY291bnRUb04rKzsKICAgICAgICAgICAgICAgIGlmIChzZXBhcmF0b3JzLkNvbnRhaW5zKHRlbXBbaV0pKSBjb3VudFRvTiA9IDA7CiAgICAgICAgICAgICAgICBlbHNlIGlmIChjb3VudFRvTiAlIG4gPT0gMCkgdGVtcFtpXSA9IHJlcGxhY2VUb1doYXQ7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIHJldHVybiBuZXcgc3RyaW5nKHRlbXApOwogICAgICAgIH0KfQ==