Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any easy way, by using regex and replaceAll method, to tranform MyFirstName by My First Name. I know I could loop through each character but I was wondering if it was possible to do that in one line.

share|improve this question
up vote 9 down vote accepted

I will answer to my own question :

String text = 'ILikeSalesforcePlatform';
text = String.valueOf(text.splitByCharacterTypeCamelCase()).replaceAll('[\\,\\(\\)]','');

Output :

USER_DEBUG|[3]|DEBUG|I Like Salesforce Platform
share|improve this answer
Well now, that is so much easier. You had to throw me off the trail by mentioning regex...I forgot all about the splitByCharacterTypeCamelCase and just assumed you had already exhausted the string methods as available options...Thanks for the question and the answer. Helps everyone stay sharp – Eric Aug 20 '14 at 0:37
Thanks anyway for your answer. I hope this will help other people. – brovasi Aug 20 '14 at 0:50
I love that Apex has splitByCharacterTypeCamelCase(). Seems so specific. – Peter Knolle Aug 20 '14 at 1:02
Haha yeah sooo specific. Longest apex method name ? – brovasi Aug 20 '14 at 7:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.