Returns invalid character in SubString method
I'm new to JS, I tried the code below,
var str = "\">2\""
var res = str.substring(2,1);
Return: >
Expected: 2
I checked this below code,
var str = "\">2\""
var res = str.substring(2);
Return: "2\"
Expected: "2\"
Please let me know if I misunderstand why it returns >instead 2. In C #, it works correctly.
Thanks in advance
In fact, you are doing wrong with her in case 1
When you do
str.substring(2,1);
It means that
str.substring(1,2);
From docs
If indexStart is larger than indexEnd, then the substring () effect looks as if both arguments were replaced; e.g. str.substring (1, 0) == str.substring (0, 1).
char 1,2 - >, .
,
str.substring(2);
str.substring(2, str.length-1);
indexEnd , substring() .