+ Start a Discussion
Elad Kaplan 3Elad Kaplan 3 

How to get character at index from a string

I have a String and I'm trying to get it's characters by index.

For some reason the method string.charAt(index) , doesn't return a letter, but a number..

Any idea how can I get the characters ?
bob_buzzardbob_buzzard
You can get at the string equivalent of the character for that index by using substring(index, index+1).  You can't really get at the characters as strings are stored as unicode which may be multi-byte, and Apex doesn't have a character type.
Hemanth SayanaHemanth Sayana
We can use substring(string.length()-1) to get last index value. To get specific index we need to modify the index using string.length()-2 or string.length()-3 and so on.
Tejas Pawar 29Tejas Pawar 29
@Elad there is one fine solution to get char from the string is to split it and then access the specified character from the output list.