how to extract the last two characters of a string?

Dear List,

can anybody help me explaining me how to extract the last 2 chars in a string? I tried to work with subString, shift, split, length and so on, but I can't get my code run.

I get a string by using event.target.name which is in my case "f_best_01".
I now want to extract the last 2 chars "01" in order to use it for further field addressing.

Thank you very much for your help,
Ralf


Ralf Könner


2 Answers

Voted Best Answer

Here's a general case:
var s = "abcd";
var suffix_s = s.substring(s.length-2);

suffix_s will be the last two characters of s.

-------------------------------------
Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


By Gilad D (try67)   

Eureka! :-)

event.target.name.substring(event.target.name.length - 2)


Ralf Könner   


Please specify a reason: