Javscript Substrings
Javscript Substrings
ok heres how javascript substrings work… an example < script language="JavaScript"> var a1, a2, input; a2="abcdefghij"; a1=a2.substring (2,6) input=prompt("Password:","");
if (input==a1) {
alert(\"correct you may enter\");
}
else {
alert:(\"wrong\");
}
}
< /script>
now to explain how it works the first line just tells the server that we are using javascript now… the 2nd line tells it that the variables a1 and a2 and for the input. the 3rd line assigns abcdefghij to the variable a2. the 4th line assigns the substring to a1. the other lines just setup an input prompt, if you type in the correct answer which is store in a1 then you get through if not you get an error
The Substring Explanation syntax:'string'.substring(non-inclusive,value.inclusive value) therefor it basicly is abcdefghij.substring(2,6); now the abcdefghij is the string and the substring will want to take some info from it. It finds out what info it needs to get from the (2,6) it tells it to take the 3rd value from the string notice it says 2 it's none inclusive and it takes all the values up to 6 and that includes the 6th value notice this time it is inclusive so our variable will have the value:- -CDEF-
Hope this helped
ghost 19 years ago
This is a nice article teaching substrings, but i would like to see Lucid_Dream (seeing as he's doing reverse code engineer articles) do a reverse code engineer on this kind of a script because it would be nice to have two different ways of accomplishing this javascript (and it would be a nice introductary lesson to reverse coding).
ghost 19 years ago
i made a slight mistake with the syntax it is: 'string'.substring(non-inclusive numeric value,inclusive numeric value) ;)