-5

Any ideas how to effeciently convert the String "TDMaturityReinvestOnNotSelected" to "TD Maturity Reinvest On Not Selected" using a java function?

Cheers Shaun

Shaun
  • 1

1 Answers1

3

This brilliant answer to RegEx to split camelCase or TitleCase (advanced) should work nicely.

Below is an excerpt from that answer:

final String pattern = "(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])";
for (String w : "TDMaturityReinvestOnNotSelected".split(pattern)) 
{
    System.out.println(w);
}

And the ouput to show it running:

Test output from demo code

Edit: You'll need to reassemble the split words with spaces, but that should be trivial to work out.

Community
  • 1
  • 1
Jason Braucht
  • 2,358
  • 19
  • 31