djp1988 Posted August 15, 2008 Share Posted August 15, 2008 How can I search to see if a string starts with "<input" please? Link to comment Share on other sites More sharing options...
jeffman Posted August 15, 2008 Share Posted August 15, 2008 if (my_string.indexOf ("<input", 0) == 0) {// YES IT DOES} Link to comment Share on other sites More sharing options...
djp1988 Posted August 15, 2008 Author Share Posted August 15, 2008 So if I read this correctly indexOf takes 2 arguments, the first being the characters you're looking for and the second being the number from which point in the string you start searching?How could that be == 0 ?Sorry to be of the sort that doesn't just sit on responses, but tries to understand everything Link to comment Share on other sites More sharing options...
jeffman Posted August 15, 2008 Share Posted August 15, 2008 Right. You pass the method the string you're searching for AND an index to begin the search on. If it finds the search string, it returns the index where the search string begins. This is more useful than a Boolean if you wanted to perform some string surgery at the return value.You specified a match only if the search string is at the start of the whole string, so we're testing for an index of zero.If the search string is not found, it returns -1 instead of false. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 15, 2008 Share Posted August 15, 2008 http://www.w3schools.com/jsref/jsref_IndexOf.asphttp://www.quirksmode.org/js/strings.html#indexof Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.