Substring


#1

"wounderful day".substring(3,7);

what is wrong with this code?


#2

write wonderful
not
wounderful
ok?? :slight_smile:
@abhijeetdesai


#3

syntax is write... output should be "derf"
if you want to see output..try this
console.log("wonderful day".substring(3,7));


#5

Except that the numbers don't match up to what the example explains. If "W" is 0, then "f" should be 6, not 7 according to the example:

Each character in a string is numbered starting from 0, like this:

0 1 2 3 4
| | | | |
h e l l o
The letter h is in position 0, the letter e is in position 1, and so on.

Therefore if you start at position 0, and slice right up till position 2, you are left with just he

but the examples below it are like the code, with the numbers being their positions if you start numbering at 1 and not 0.


#6

I think it's better way to remember
first substring number is array position
and
second substring number is string position

@ajaxslayer72965_507b


#7

Hey, are blank spaces counted as numbers when using substrings in Javascript?


#8

They are counted as characters, just like numbers and letters are.


#12