What would be the quickest way to remove "everything" from a string, starting from the first "dot".
For example:
This.Is.A.Test
=> would become
This
What would be the quickest way to remove "everything" from a string, starting from the first "dot".
For example:
This.Is.A.Test
=> would become
This
You can use the the split() function like this:
"This.Is.A.Test".split(".")[0]; // will work even if there are no dots
Or you could use the substr() function in combination with the indexOf() function, like this:
var myStr = "This.Is.A.Test";
var justTheFirstBit = myStr.substr(0, myStr.indexOf(".")); // needs 1 dot minimum
substring function for you.substr is just as valid as substring. I'll be changing it back, although I appreciate the edit. :)"This.Is.A.Test".replace(/\..+$/,""); is better.substr() being frowned upon.Alternatively,
var string = "This.Is.A.Test";
var newstring = string.substring(0, string.indexOf("."));
$('#el').text( $('#el').text().split('.')[0] );
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/split
You can use the the replace() function like this:
"This.Is.A.Test".replace(/\..+$/,"");
This is the regular expression you need:
/\..+$/