<html> <body> <script type="text/javascript"> var str="Java Scripting is great!" var pos=str.indexOf("School") if (pos>=0) { document.write("School found at position: ") document.write(pos + "<br />") } else { document.write("School not found!") } </script> <p>This example tests if a string contains a specified word. If the word is found it returns the position of the first character of the word in the original string. Note: The first position in the string is 0!</p> </body> </html>
Edit the text above, and click on the button to see the result.
Copyright © 2007-2008, Www.JavaBasics.We.Bs All rights reserved.