Friday 7 February 2014

How to split string on the first white space in Salesforce


Consider the following string,

Input:
Only for Salesforce

I need to get the desired output like,

Output:
Only = String 1
For salesforce = String 2

If you want to split string on the first white space means consider the following method,

  1. String str =’Only for Salesforce’;
  2. String str1,str2;

  3. str1=str.substring(0,str.indexOf(' '));
  4. str2=str.substring(str.indexOf(' ')+1);

  5. system.debug(String 1 ## ' + str1);  // returns Only
  6. system.debug('String 2 ##' + str2);  // returns for Salesforce

No comments:

Post a Comment

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...