title: How should I implement a substring function in java?
body: <p>Consider you have been told to implement a kind of the java String.substring method.<br>
  The signature of the method is as follows:  </p>
  
  <p><strong>public static boolean isSubstring(String i_StringForSearch, String i_SubStringToFind)</strong>  </p>
  
  <p>Here is my solution, but I feel it's still not the best elegant solution I could have.(Many canonical if else's)<br>
  What do you think? Would you do it in another way?</p>
  
  <pre><code>public static boolean isSubstring(String i_StringForSearch, String i_SubStringToFind)
      {
          int strForSearchIndex = 0;
          int subStrToFindIndex = 0;
          boolean endOfStringToSearch = false;
          boolean foundSubString = false;
          boolean isThereASequenceOfMatching = false;
  
  
          while(!endOfStringToSearch &amp;&amp; !foundSubString)
          {
              if(strForSearchIndex == i_StringForSearch.length())
              {
                  endOfStringToSearch = true;
              }
  
              else if(i_StringForSearch.charAt(strForSearchIndex) == i_SubStringToFind.charAt(subStrToFindIndex))
              {
                  isThereASequenceOfMatching = true;
                  if(subStrToFindIndex == i_SubStringToFind.length() -1 )
                  {
                      foundSubString = true;
                  }
                  subStrToFindIndex++;
                  strForSearchIndex++;
              }
  
              else if(i_StringForSearch.charAt(strForSearchIndex) != i_SubStringToFind.charAt(subStrToFindIndex))
              {
                  if(isThereASequenceOfMatching)
                  {
                      subStrToFindIndex = 0;
                      isThereASequenceOfMatching = false;
                  }
                  strForSearchIndex++;
              }
          }
  
         return foundSubString;
      }
  </code></pre>