I need to split a CamelCase string into an array of words based on the case of the letters. The rules for dividing the string are as follows:
- Break the string in all places where a lowercase letter is followed by an uppercase letter, and break before the uppercase letter.
- e.g.:
aB
->{ "a", "B" }
- e.g.:
helloWorld
->{ "hello", "World" }
- e.g.:
- Break the string in all places where an uppercase letter is followed by a lowercase letter, and break before the uppercase letter.
- e.g.:
ABc
->{ "A", "Bc" }
- e.g.:
HELLOWorld
->{ "HELLO", "World" }
- e.g.:
Some edge cases deserve examples of expected output:
FYYear
->{ "FY", "Year" }
CostCenter
->{ "Cost", "Center" }
cosTCenter
->{ "cos", "T", "Center" }
CostcenteR
->{ "Costcente", "R" }
COSTCENTER
->{ "COSTCENTER" }
I've tried using a regular expression as shown in the code below:
updateCaption = string.Join(" ", Regex.Split(updateCaption, @"(?<!^)(?=[A-Z])"));
But this doesn't work.