Substring Method in JavaScript
We used over 10 web hosting companies before we found Server Intellect. They offer dedicated servers, and they now offer cloud hosting!
The Substring Method in JavaScript can also be applied to Visual Basic, as well as Visual C Sharp, C#. What the Substring Method does is it allows you to take sections a.k.a. parse, whether its singular words or full phrases, and create a new string or unleash your will upon it. Using this in conjunction with the IndexOf Method will let you find where the variable, section of the string you are looking for, is located.Let begin with a quick example. Let’s take the string, “Do I love pie?” and answer the question.
var s = "Do I love pie?";
var w = "I";
var index = s.indexOf(w);
ns = s.substring(index, s.length -1) + "." ;
alert(index);
document.body.innerHTML = ns;
We stand behind Server Intellect and their support team. They offer dedicated servers, and they are now offering cloud hosting!
I have then also put in an alert to help you understand what steps are taking place. This alert will display the IndexOf “w” in our original string.And lastly, we will be writing our new string to the body of our HTML document.
You have now learned how to parse out a section of a string and manipulate it to do whatever you please, in this case, answer a question in code!
If you still feel a bit confused or don’t understand the subject matter, please don’t hesitate to download the Source Code provided at the bottom. I have included some other examples as well to help illustrate some other possibilities of the Substring Method. Thank you for joining me and I hope you have found this useful. Take care and until next time.
We chose Server Intellect for its cloud hosting, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
SubStringTut.zip