Take the 2-minute tour ×
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.

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

1 Answer 1

up vote 9 down vote accepted

I will answer to my own question :

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

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

Your Answer

 
discard

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.