+ Start a Discussion
plapla 

String/sub string function

Hello,

 

I want to get the far right single character of the string of characters below. It is a character Y in this case. What string/sub string function is best for this? Please advise. Any help is appreciated.

 

Examle:  1234ALOCN78UY

 

Thanks

Paul

 

Best Answer chosen by Admin (Salesforce Developers) 
amarcuteamarcute

Hi,

 

You can try using right() method as shown below:

 

String s1 = '1234ALOCN78UY';
String s2 = 
   s1.right(1);
System.assertEquals(
   'Y', s2);

All Answers

amarcuteamarcute

Hi,

 

You can try using right() method as shown below:

 

String s1 = '1234ALOCN78UY';
String s2 = 
   s1.right(1);
System.assertEquals(
   'Y', s2);
This was selected as the best answer
plapla

Thank you. It worked.