I need to find the last occurrence of the character comma for retrieve last word of a text field.
Example.
Text field: Discovery 3.0 SDV6 188KW Diesel (HP) SE, Italy ITA, HSVH/350HG, **2012**
The formula results get last word: 2012
I need to find the last occurrence of the character comma for retrieve last word of a text field.
Example.
Text field: Discovery 3.0 SDV6 188KW Diesel (HP) SE, Italy ITA, HSVH/350HG, **2012**
The formula results get last word: 2012
Query the Object and your text field and use the below code snippet. This should work for you.
List<String> lstStr = Your_Object_name.Your_File.Name.split(',');
system.debug('--Your desired Result--'+lstStr[lstStr.size()-1]);
For anyone finding this question in the future:
if it's a field value you can do this:
RIGHT(Field__c,FIND(",",REVERSE(Field__c ))-1)
Finding the last occurrence by reversing the text and finding the first. RIGHT will than take the index of the found position and return what follows, we subtract 1 so the actual "," will be skipped.
you might want to use TRIM to remove access white spaces.
TRIM(RIGHT(Field__c,FIND(",",REVERSE(Field__c ))-1))