+ Start a Discussion
SalesRedSalesRed 

Equivalent String Function to charAt() ?

Hello,

 

I was wondering if there is any equivalent string function that can used similar to the charAt function which exists in java?

I know no such method is listed at http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm

 

I know it's possible to look through the string and to get each character using the substring function in such a loop but it would be much better if a function existed similar to charAt.

 

if anyone knows of a better way of doing this you can let me know.

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
Platy ITPlaty IT

You can use substring the same way you would charAt, it doesn't have to be in a loop.  If you know exactly which character(s) you're trying to grab, substring just requires 2 inputs to get it, the start and end position.  So...

 

charAt(4) is the same as substring(3,4)

All Answers

Platy ITPlaty IT

You can use substring the same way you would charAt, it doesn't have to be in a loop.  If you know exactly which character(s) you're trying to grab, substring just requires 2 inputs to get it, the start and end position.  So...

 

charAt(4) is the same as substring(3,4)

This was selected as the best answer
keniam cresti 5keniam cresti 5
Thanks for sharing this valuable info. TalkToSonic Survey