Skip to main content
Notice removed Reward existing answer by DLosc
Bounty Ended with Baby_Boy's answer chosen by DLosc
Notice added Reward existing answer by DLosc
Bounty Started worth 200 reputation by DLosc
added 7 characters in body; edited title
Source Link
anoman
  • 349
  • 2
  • 7

Remove a given substringthe last 'n' numberoccurences of timesa substring from the end of a string

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

  1. The shortest code wins the challenge (as this is ).

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."

Remove a given substring 'n' number of times from the end of a string

Given a string and a substring and a positive integer n.

Remove the n duplicates of 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

  1. The shortest code wins the challenge (as this is ).

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."

Remove the last 'n' occurences of a substring from a string

Given a string and a substring and a positive integer n.

Remove the n occurences 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

  1. The shortest code wins the challenge (as this is ).

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."
Tweeted twitter.com/StackCodeGolf/status/1585103938629533697
Format test cases code wall; Add another test case based on the rules in the question
Source Link

Given a string and a substring and a positive integer n.

Remove the n duplicates of 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

  1. The shortest code wins the challenge (as this is ).

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."

Given a string and a substring and a positive integer n.

Remove the n duplicates of 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

  1. The shortest code wins the challenge (as this is ).

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."

Given a string and a substring and a positive integer n.

Remove the n duplicates of 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

  1. The shortest code wins the challenge (as this is ).

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."
Became Hot Network Question
assumed default I/O and test cases, removed ambiguous rule
Source Link

The user inputsGiven a string and a substring. They also input and a positive integer 'n'n.

Remove the 'n'n duplicates of substring from the endend 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'n, then the output is the original string. No space should be present in place of the removed substring.

RULES

  1. This challenge is for only basic problem solving skills. Hence, You are only allowed to use in-built functions and no outer modules shall be used.The more basic and straightforward the code, the higher it is appreciated.

  2. The shortest code wins the challenge.

    The shortest code wins the challenge (as this is ).

Example 1

Input:

String = "Cats do meow-meow while lions do not meow."

Substring = "meow"

n = 2

Output:

"Cats do meow- while lions do not ."

Example 2Test-cases:

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 = 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."

The user inputs a string and a substring. They also input a positive integer 'n'.

Remove the 'n' duplicates of 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

  1. This challenge is for only basic problem solving skills. Hence, You are only allowed to use in-built functions and no outer modules shall be used.The more basic and straightforward the code, the higher it is appreciated.

  2. The shortest code wins the challenge.

Example 1

Input:

String = "Cats do meow-meow while lions do not meow."

Substring = "meow"

n = 2

Output:

"Cats do meow- while lions do not ."

Example 2

Input:

String = "Cats do not memeowow, they do meow-ing."

Substring = "meow"

n = 2

Output:

"Cats do not meow, they do -ing."

Given a string and a substring and a positive integer n.

Remove the n duplicates of 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

  1. The shortest code wins the challenge (as this is ).

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."
Post Reopened by mousetail 'he-him', Kevin Cruijssen, t-clausen.dk, Arnauld, rydwolf
Left closed in review as "Original close reason(s) were not resolved" by Wheat Wizard
added 186 characters in body
Source Link
anoman
  • 349
  • 2
  • 7
Loading
Post Closed as "Needs details or clarity" by xnor, lyxal, Kirill L., DialFrost, pxeger
Formatting
Source Link
mousetail 'he-him'
  • 13.5k
  • 1
  • 39
  • 85
Loading
edited tags
Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading
Source Link
anoman
  • 349
  • 2
  • 7
Loading