Logo

Programming-Idioms

History of Idiom 46 > diff from v17 to v18

Edit summary for version 18 by :

Version 17

2015-09-04, 00:46:14

Version 18

2015-09-09, 08:50:52

Idiom #46 Extract beginning of string (prefix)

Create string t consisting of the 5 first characters of string s.

Idiom #46 Extract beginning of string (prefix)

Create string t consisting of the 5 first characters of string s.

Code
var t = s.substring(0,5);
Code
var t = s.substring(0,5);
Comments bubble
s.substr(0,5) would also work in that speicific case.
Comments bubble
s.substr(0,5) would also work in that specific case.
Doc URL
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/substring
Doc URL
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/substring