Advertisement
RokiAdhytama

Searching Strings - Chapter 12-1

Jul 4th, 2022
799
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html xmlns = "http://www.w3.org/1999/xhtml">
  2.    <head>
  3.       <title>
  4.          Searching Strings with indexOf and lastIndexOf
  5.       </title>
  6.  
  7.       <script type = "text/javascript">
  8.          <!--
  9.          var letters = "abcdefghijklmnopqrstuvwxyzabcdefghijklm";
  10.          
  11.          function buttonPressed()
  12.          {
  13.             searchForm.first.value =
  14.                letters.indexOf( searchForm.inputVal.value );
  15.             searchForm.last.value =
  16.                letters.lastIndexOf( searchForm.inputVal.value );
  17.             searchForm.first12.value =
  18.                letters.indexOf( searchForm.inputVal.value, 12 );
  19.             searchForm.last12.value =
  20.                letters.lastIndexOf(
  21.                   searchForm.inputVal.value, 12 );
  22.          }
  23.          // -->
  24.       </script>
  25.  
  26.    </head>
  27.    <body>
  28.       <form name = "searchForm" action = "">
  29.          <h1>The string to search is:<br />
  30.              abcdefghijklmnopqrstuvwxyzabcdefghijklm</h1>
  31.          <p>Enter substring to search for
  32.          <input name = "inputVal" type = "text" />
  33.          <input name = "search" type = "button" value = "Search"
  34.                 onclick = "buttonPressed()" /><br /></p>
  35.      
  36.          <p>First occurrence located at index
  37.          <input name = "first" type = "text" size = "5" />
  38.          <br />Last occurrence located at index
  39.          <input name = "last" type = "text" size = "5" />
  40.          <br />First occurrence from index 12 located at index
  41.          <input name = "first12" type = "text" size = "5" />
  42.          <br />Last occurrence from index 12 located at index
  43.          <input name = "last12" type = "text" size = "5" /></p>
  44.       </form>
  45.    </body>
  46. </html>
Advertisement
RAW Paste Data Copied
Advertisement