3

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

8
  • after last comma always you will get Year ie. 2012 or 2015 or 2016 ?
    – Ratan Paul
    Commented Feb 12, 2016 at 16:10
  • the year is not the same for all records
    – maidenfp
    Commented Feb 12, 2016 at 16:11
  • Means it will only last 4 character correct?
    – Ratan Paul
    Commented Feb 12, 2016 at 16:14
  • It may be that the year also contains other characters. I'm interested in all the characters after the last comma
    – maidenfp
    Commented Feb 12, 2016 at 16:15
  • 1
    this is a very fragile solution as I'm sure you realize as it is dependent on # of commas in text field; apex is more robust (a before insert/update trigger)
    – cropredy
    Commented Feb 12, 2016 at 17:40

2 Answers 2

1

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]);
0

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))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .