6
1
Challenge
In this challenge, you are to code in any language a program or function that will take a string and replace certain characters within it with different characters.
Input
The input is the same for both functions and full programs:
[string] [char1] [char2]
stringwill be an indefinite line of characters surrounded by quotation mars, such as "Hello, World!" or "1 plus 2 = 3".char1will be a single character withinstring.char2will be a single character not necessarily instring.
Output
[modified string]
Your output will take string and replace all instances of char1 with char2, then output the result as modified string. Case should be ignored, so the input "yolO" o u should output yulu.
Examples
Input
"Hello, World!" l r
Output
Herro, Worrd!
Input
"Slithery snakes slurp Smoothies through Silly Straws" s z
Output
zlithery znakez zlurp zmoothiez through zilly ztrawz
Input
"Grant Bowtie: Only the best future bass artist ever" : -
Output
Grant Bowtie- Only the best future bass artist ever
Input
"019 + 532 * 281 / ? = waht/?" / !
Output
019 + 532 * 281 ! ? = waht!?
Other details
This is code golf, so the shortest answer (in bytes) at the end of the week (the 14th of September) wins. Also, anything not specified in this challenge is fair game, meaning that stuff I don't explain is up to you.
I figure the two characters can be upper case as well? And if the first of the two is upper case, it would still match both lower and upper case characters in the string? – Reto Koradi – 2015-09-08T02:34:06.077
4Are functions allowed? – Downgoat – 2015-09-08T03:22:55.087
To add to vihan's comment, note that per our defaults, functions or full programs are both okay.
– Alex A. – 2015-09-08T03:25:07.3172@AlexA. Isn't that only if it's not specified? In this case, it says "a program". In the past, that meant that you had to provide a full program. – Reto Koradi – 2015-09-08T03:27:02.293
@RetoKoradi - unfortunately, different people use the term "program" differently. So "in the past" is only relevant if it was the same person (the_basset_hound). – Glen O – 2015-09-08T03:42:25.363
What about the quotes in the input? I guess they have to be removed, haven't they? – Cabbie407 – 2015-09-08T04:40:10.203
@RetoKoradi All replaced characters should be lowercase, regardless of the case of the two characters. – The_Basset_Hound – 2015-09-08T05:02:55.227
2@vihan Functions are allowed. – The_Basset_Hound – 2015-09-08T05:03:18.470
1@Cabbie407 The quotes will need to be accounted for, yes. – The_Basset_Hound – 2015-09-08T05:05:06.207
6So the second character can be upper case, and the replaced character is lower case? That doesn't make much sense to me. So if functions are allowed, but it specifically says that the input string has quotes, will the function receive a string that has quotes inside the string? Well, frankly, I'm probably done with this challenge anyway. Changing about 3 rules after there are already 10 answers is very unfortunate. – Reto Koradi – 2015-09-08T05:34:05.497
4That part about all replacements needing to be lowercase is new. The original statement said, that case should be ignored. For me this means, that lower and upper case letters should be replaced, but not that I should change the replacement letter... – Cabbie407 – 2015-09-08T05:35:35.327
Does input have to come from stdin or from command line arguments? If stdin, do the three items have to be separated by a single space each, or are other delimiters acceptable? – ThisSuitIsBlackNot – 2015-09-08T17:17:55.963
1@RetoKoradi How about this (and I'll put this and other info in the question): Anything not specified about the challenge is fair game. – The_Basset_Hound – 2015-09-08T22:31:00.947