↧
Answer by Jonathan for Get everything after the dash in a string in JavaScript
Efficient, compact and works in the general case:s='sometext-20202's.slice(s.lastIndexOf('-')+1)
View ArticleAnswer by Bhanusri Kokala for Get everything after the dash in a string in...
To use any delimiter and get first or second part //To divide string using deimeter - here @ //str: full string that is to be splitted //delimeter: like '-' //part number: 0 - for string befor...
View ArticleAnswer by aturan23 for Get everything after the dash in a string in JavaScript
You can use split method for it. And if you should take string from specific pattern you can use split with req. exp.:var string = "sometext-20202";console.log(string.split(/-(.*)/)[1])
View ArticleAnswer by axwr for Get everything after the dash in a string in JavaScript
Everyone else has posted some perfectly reasonable answers. I took a different direction. Without using split, substring, or indexOf. Works great on i.e. and firefox. Probably works on Netscape...
View ArticleAnswer by Steve for Get everything after the dash in a string in JavaScript
For those trying to get everything after the first occurrence:Something like "Nic K Cage" to "K Cage".You can use slice to get everything from a certain character. In this case from the first...
View ArticleAnswer by Leon Williams for Get everything after the dash in a string in...
I came to this question because I needed what OP was asking but more than what other answers offered (they're technically correct, but too minimal for my purposes). I've made my own solution; maybe...
View ArticleAnswer by Mahyar Ekramian for Get everything after the dash in a string in...
With built-in javascript replace() function and using of regex (/(.*)-/), you can replace the substring before the dash character with empty string (""):"sometext-20202".replace(/(.*)-/,""); // result...
View ArticleAnswer by kcsoft for Get everything after the dash in a string in JavaScript
myString.split('-').splice(1).join('-')
View ArticleAnswer by Kanke for Get everything after the dash in a string in JavaScript
var testStr = "sometext-20202"var splitStr = testStr.substring(testStr.indexOf('-') + 1);
View ArticleAnswer by RPL for Get everything after the dash in a string in JavaScript
A solution I prefer would be:const str = 'sometext-20202';const slug = str.split('-').pop();Where slug would be your result
View ArticleAnswer by artlung for Get everything after the dash in a string in JavaScript
How I would do this:// function you can use:function getSecondPart(str) { return str.split('-')[1];}// use the function:alert(getSecondPart("sometext-20202"));
View ArticleAnswer by Cerebrus for Get everything after the dash in a string in JavaScript
AFAIK, both substring() and indexOf() are supported by both Mozilla and IE. However, note that substr() might not be supported on earlier versions of some browsers (esp. Netscape/Opera).Your post...
View ArticleAnswer by dirkgently for Get everything after the dash in a string in JavaScript
Use a regular expression of the form: \w-\d+ where a \w represents a word and \d represents a digit. They won't work out of the box, so play around. Try this.
View ArticleAnswer by Sean Bright for Get everything after the dash in a string in...
var the_string = "sometext-20202";var parts = the_string.split('-', 2);// After calling split(), 'parts' is an array with two elements:// parts[0] is 'sometext'// parts[1] is '20202'var the_text =...
View ArticleGet everything after the dash in a string in JavaScript
What would be the cleanest way of doing this that would work in both IE and Firefox?My string looks like this sometext-20202Now the sometext and the integer after the dash can be of varying...
View Article
More Pages to Explore .....