<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>Javascript has two string methods (`substr` and `substring`) that appear to be identical at first glance; they both return a substring from a given string. So what's the difference? 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 = "string";
    s.substring(1, 3); // would return 'tr'
    
    var s = "another example";
    s.substring(3, 7); // would return 'ther'

When using `substr` the second parameter is the number of characters to include in the substring:

    var s = "string";
    s.substr(1, 3); // would return 'tri'
    
    var s = "another example";
    s.substr(3, 7); // would return 'ther ex'

For more information on string functions, checkout [Quirksmode's guide](http://www.quirksmode.org/js/strings.html).</body>
  <created-at type="datetime">2009-06-03T23:03:31+10:00</created-at>
  <id type="integer">37</id>
  <project-id type="integer" nil="true"></project-id>
  <published type="boolean">true</published>
  <published-at type="datetime">2008-05-24T18:00:00+10:00</published-at>
  <title>Javascript: Difference between substr and substring</title>
  <updated-at type="datetime">2009-06-03T23:03:31+10:00</updated-at>
  <url>javascript-difference-between-substr-and-substring</url>
</post>
