Another Salesforce blog!!!

Salesforce, Apex

capitalizing 1st character of each word in a string


String rep_name = 'this is a test';
List<String> elems = rep_name.split(' ');
rep_name = '';
for (String x : elems)
{
    rep_name += x.substring(0,1).toUpperCase()+x.substring(1,x.length()) + ' ';
}
System.debug('>>>'+rep_name);

Replace ‘_’ with space?:

string sText = 'ancestor_concept_id';
sText = sText.replaceAll( '_', ' ');

Leave a Reply

Your email address will not be published. Required fields are marked *

*