Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String manipulation - getting value after the last position of a char

How I can get the value after last char(. ; + _ etc.): e.g.

string.name+org.com

I want to get "com". Is there any function in jQuery?

like image 488
beetle Avatar asked Mar 23 '12 12:03

beetle


1 Answers

Use lastIndexOf and substr to find the character and get the part of the string after it:

var extension = name.substr(name.lastIndexOf(".") + 1);

Demo: http://jsfiddle.net/Guffa/K3BWn/

like image 160
Guffa Avatar answered Oct 21 '22 03:10

Guffa