Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string RemoveRecursiveChar(string input, char ch, int keepCount)
- {
- var len = input.Length;
- var chars = new char[len];
- var writeIndex = 0;
- var charCount = 0;
- for (var j = 0; j < len; j++)
- {
- if (input[j] != ch)
- {
- chars[writeIndex++] = input[j];
- charCount = 0;
- }
- else if (charCount + 1 <= keepCount)
- {
- chars[writeIndex++] = ch;
- charCount++;
- }
- }
- return new string(chars, 0, writeIndex);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement