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.

1 Answer 1


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
  • 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, 2014 at 0:37
  • Thanks anyway for your answer. I hope this will help other people.
    – brovasi
    Aug 20, 2014 at 0:50
  • I love that Apex has splitByCharacterTypeCamelCase(). Seems so specific. Aug 20, 2014 at 1:02
  • Haha yeah sooo specific. Longest apex method name ?
    – brovasi
    Aug 20, 2014 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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