Quantcast
Channel: What is the difference between substr and substring? - Stack Overflow
Browsing latest articles
Browse All 12 View Live

Answer by Dr Nisha Arora for What is the difference between substr and...

EDIT: This answer is with reference to R programmingHere are major differences between substr() and substring():substr() has arguments start & stop while substring as arguments first &...

View Article



Answer by Gaurav for What is the difference between substr and substring?

let str = "Hello World"console.log(str.substring(1, 3)) // el -> Excludes the last indexconsole.log(str.substr(1, 3)) // ell -> Includes the last index

View Article

Answer by Sajith Mantharath for What is the difference between substr and...

substring(startIndex, endIndex(not included))substr(startIndex, how many characters)const string = 'JavaScript';console.log('substring(1,2)', string.substring(1,2)); // aconsole.log('substr(1,2)',...

View Article

Answer by raju poloju for What is the difference between substr and substring?

substring():It has 2 parameters "start" and "end". start parameter is required and specifies the position where to startthe extraction. end parameter is optional and specifies the position where...

View Article

Answer by Nate Lipp for What is the difference between substr and substring?

The main difference is thatsubstr() allows you to specify the maximum length to returnsubstring() allows you to specify the indices and the second argument is NOT inclusiveThere are some additional...

View Article


Answer by 5ervant - techintel.github.io for What is the difference between...

The big difference is, substr() is a deprecated method that can still be used, but should be used with caution because they are expected to be removed entirely sometime in the future. You should work...

View Article

Answer by CurnalCurz for What is the difference between substr and substring?

The difference is second parameter. Their second parameters, while both numbers, are expecting two different things:When using substring the second parameter is the first index not to include:var s =...

View Article

Answer by JefferMC for What is the difference between substr and substring?

As hinted at in yatima2975's answer, there is an additional difference:substr() accepts a negative starting position as an offset from the end of the string. substring() does not.From MDN:If start is...

View Article


Answer by yatima2975 for What is the difference between substr and substring?

Another gotcha I recently came across is that in IE 8, "abcd".substr(-1) erroneously returns "abcd", whereas Firefox 3.6 returns "d" as it should. slice works correctly on both.More on this topic can...

View Article


Answer by Colin Hebert for What is the difference between substr and substring?

substr (MDN) takes parameters as (from, length).substring (MDN) takes parameters as (from, to).Update: MDN considers substr legacy.alert("abc".substr(1,2)); // returns "bc"alert("abc".substring(1,2));...

View Article

Answer by Delan Azabani for What is the difference between substr and substring?

The difference is in the second argument. The second argument to substring is the index to stop at (but not include), but the second argument to substr is the maximum length to...

View Article

What is the difference between substr and substring?

What is the difference betweenalert("abc".substr(0,2));andalert("abc".substring(0,2));They both seem to output “ab”.

View Article
Browsing latest articles
Browse All 12 View Live




Latest Images