以三个输入,文本串T
; 一串要替换的字符F
;以及用替换它们的字符串R
。对于每个T
具有相同(不区分大小写)字符的子字符串F
,请将其替换为中的字符R
。但是,请保持与原始文本相同的大小写。
如果输入的字符R
多于个F
,则多余的字符应与输入的大小写相同R
。如果其中包含数字或符号F
,则其中的相应字符R
应保持其大小写R
。F
不一定会出现在中T
。
您可以假设所有文本都在可打印的ASCII范围内。
例子
"Text input", "text", "test" -> "Test input"
"tHiS Is a PiEcE oF tExT", "is", "abcde" -> "tHaBcde Abcde a PiEcE oF tExT"
"The birch canoe slid on the smooth planks", "o", " OH MY " -> "The birch can OH MY e slid OH MY n the sm OH MY OH MY th planks"
"The score was 10 to 5", "10", "tEn" -> "The score was tEn to 5"
"I wrote my code in Brain$#@!", "$#@!", "Friend" -> "I wrote my code in BrainFriend"
"This challenge was created by Andrew Piliser", "Andrew Piliser", "Martin Ender" -> "This challenge was created by Martin Ender"
// Has a match, but does not match case
"John does not know", "John Doe", "Jane Doe" -> "Jane does not know"
// No match
"Glue the sheet to the dark blue background", "Glue the sheet to the dark-blue background", "foo" -> "Glue the sheet to the dark blue background"
// Only take full matches
"aaa", "aa", "b" -> "ba"
// Apply matching once across the string as a whole, do not iterate on replaced text
"aaaa", "aa", "a" -> "aa"
"TeXT input", "text", "test" -> "TeST input"
"The birch canoe slid on the smooth planks", "o", " OH MY "
这么幽默,但是我喜欢那个例子。
"TeXT input", "text", "test"