Truncate all but the chars after a "_"

I have a string I am reading in, and all I care about is what comes after the final "_":

Before:

ctl00_ContentPlaceHolder1_create_new_user_BillingInfo_tbFirstName

After:

tbFirstName


Many thanks!

Tom
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
leakim971PluritechnicianCommented:
var str = "ctl00_ContentPlaceHolder1_create_new_user_BillingInfo_tbFirstName";
var last = str.split("_").pop();

http://www.w3schools.com/jsref/jsref_obj_array.asp
0
 
haloexpertsexchangeCommented:
var string = "ctl00_ContentPlaceHolder1_create_new_user_BillingInfo_tbFirstName";
var last = string.lastIndexOf("_");
var lookedFor = string.substr(last);
lookFor should have tbFirstName

Open in new window

0
 
chaitu chaituCommented:
alert(x.substring(x.lastIndexOf('_')+1,x.length));
0
 
chaitu chaituCommented:
alert(x.substring(x.lastIndexOf('_')+1));
0
 
Tom KnowltonWeb developerAuthor Commented:
I liked leakim971's answer best, but it' nice to have alternatives!

Thanks everyone!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.