+ Start a Discussion

strip last word from text field and convert to integer

I have a text_field__c which always ends in 1 or 2 or 3

Eg: Step is 1
    Step is 2
    Step is 3

How can I get the last word i.e 1 or 2 or 3 from the text and then convert the text into integer value?

Is this possible?  


Use string method "string".substring() to take the last character from your string and then use Integer.valueOf() to convert that to an integer...

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

or you can do something like..


string s = 'step is 101';
List<String> ss = new List<String>();
ss=s.split(' ',0);
system.debug('List Last Element>>'+ss.get(ss.size()-1)); // gives you last word of the string then you can convert into integer as required...




Thanks @Sorna and @Sam_SFDC15

I will try and let you know.. Much appreciated!!