Syntax for IndexOf()
string.indexOf(searchstring, start)
Here search string is the character that is to be find and start is the position from which search to begin.
Example of IndexOf() Method [JavaScript]:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function GetStringIndex() {
var str="Javascript IndexOf Method.";
document.write( "a is at position"+ str.indexOf("a") + "<br />");
document.write("IndexOf is at position"+ str.indexOf("IndexOf") + "<br />");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="Submit" onclick="return GetStringIndex();" />
</div>
</form>
</body>
</html>
//Output< //a is at position 1 //IndexOf is at position 11
No comments:
Post a Comment