Challenge :
Given a string split at specific positions and capitalize the first character of the given word. Capitalize the first word's first char if and only if it was already capitalized
Input :
A string s
and a character c
.
Ouput :
The string with each occurrence of c
replaced with the first char capitalized
Examples :
STRING(s) CHARACTER(c) RESULT
Hello_world _ HelloWorld
me,no,like , meNoLike
you-got-it - youGotIt
Am^I^clear ^ AmIClear
go!full!caps ! goFullCaps
weird&but&tRue & weirdButTRue
ProbleM1fixed1no 1 ProbleMFixedNo
!prob!!lem!s!Olved!! ! ProbLemSOlved
Note :
- Given input will always be valid. i.e : The first will always be a string with at least one instance of the character to replace at. The second will always will be a single character.
- The length of the input string will be greater 4.
There will be at least one occurrence of the character to split at.
The input is guaranteed to contain only letters and the separator (Thanks @Arnauld)
- Separator is anything that is not an alphabet (a-z / A-Z) (suggested by @Dennis)
Winning criteria :
This is code-golf so shortest code in bytes for each language wins.
- Thanks to @JonathanAllan for pointing out two mistakes.
1
). Try to think about how solutions might fail, and make a test case for such situations. Some examples: Letters as separators, the separator being the last character, consecutive separators and so on. There's no need to have many test cases that doesn't test different things. \$\endgroup\$.
, I can imagine some string splitting functions struggling with that one. \$\endgroup\$