Given a string and a substring and a positive integer n
.
Remove the n
duplicatesoccurences of a substring from the end of the originally given string. If the substring is not present in the string or the number of times the substring appears is less than n
, then the output is the original string. No space should be present in place of the removed substring.
RULES
- The shortest code wins the challenge (as this is code-golf).
Test-cases:
Input:
String = "Cats do meow-meow while lions do not meow."
Substring = "meow"
n = 2
Output:
"Cats do meow- while lions do not ."
Input:
String = "Cats do not memeowow, they do meow-ing."
Substring = "meow"
n = 2
Output:
"Cats do not meow, they do -ing."
Input:
String = "Cats do meow-meow while lions do not meow."
Substring = "meow"
n = 4
Output:
"Cats do meow-meow while lions do not meow."