Separate strings in a Text field using Apex

 

Separate strings in a Text field using Apex:


Suppose there is an array of Items: a1a2a3, and so on

Use a formula to split out the individual item's into separate fields like:
  1. field1 will show the first item in the array (a1)
  2. field2 will show the second item  in the array (a2)
  3. field3 will show the third item in the array (a3)
  4. and so on


Solution:


List<String> items = o.ProductList__c.split(',');
List<String> fNames = new List<String> { 'a1__c', 'a2__c', so on };
for (Integer i = 0; i < items.size() && i < fNames.size(); i++) {
   o.put(fNames[i], items[i]);
}


Another Example:

Field1 : q:1234

Field2 : z: 2347


Lets separate  separate the test based on ':' 


RIGHT(Field_Name__c,(LEN(Field_Name__c)-FIND(":", Field_Name__c)))

Comments