Using the JavaScript IndexOf Method
We used over 10 web hosting companies before we found Server Intellect. They offer dedicated servers, and they now offer cloud hosting!
Let’s begin with the most simple and another “Hello World”, yes I know, you must be overwhelmed with joy; and yes, that is sarcasm for those of you that didn’t pick up what I was putting down. All you will need is an HTML file and it is optional if you would like to use an external JavaScript page as well, I will be to keep the code a bit more readable.First what we will need to do is establish a string variable that has the value of, drum roll, yes; you guessed it “Hello World.” Once we have done so I will be writing the variable to screen like so:
window.onload = function () {
var str = "Hello world!";
document.write(str + "<br/>");}
Now, what we will find the IndexOf the letter “d” in our variable. Now, what we need to remember that the first position in the string is “0,” not “1”.
We stand behind Server Intellect and their support team. They offer dedicated servers, and they are now offering cloud hosting!
document.write("IndexOf the letter 'd' in Hello world is : " + str.indexOf("d") + "<br />");
Then what we will do is take the IndexOf the same Variable but this time we will set the “Start ” parameter to that of the IndexOf the first use plus the length of the variable itself, like so:
var myString = "This is my new string in which i will repeat the word string one more time.";
var w = "string";
document.write(myString + "<br/>");
document.write("IndexOf the word 'string' in myString is : " + myString.indexOf(w) + "<br/>");
document.write("IndexOf the second use of the word 'string' in myString is : " + myString.indexOf(w, myString.indexOf(w) + w.length) + "<br/>");
We used over 10 web hosting companies before we found Server Intellect. Our new server with cloud hosting,was set up in less than 24 hours. We were able to confirm our order over the phone. They responded to our inquiries within an hour. Server Intellect’s customer support and assistance are the best we’ve ever experienced.
JavascriptIndexOfTut.zip