• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 141
  • Last Modified:

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
0
Tom Knowlton
Asked:
Tom Knowlton
3 Solutions
 
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
 
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
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now