title: C# System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex')
body: <p>Unhandled exception:</p>
  <blockquote>
  <p>System.ArgumentOutOfRangeException: startIndex cannot be larger than
  length of string. (Parameter 'startIndex')    at
  System.String.Substring(Int32 startIndex, Int32 length)    at
  Film_Libary.Registration.Login() in /Users/elliot/Documents/Film
  Libary Software/Film-Libary/Film-Libary/Registration.cs:line 75</p>
  </blockquote>
  <p>This error occurs when im trying to validate the user infomation of username and password from the text file to what they inputted</p>
  <pre><code>
  
  
  public void Login()
          {
  
              string fileName = @&quot;/Users/elliot/Documents/Film Libary Software/Film-Libary/Film-Libary/bin/Debug/netcoreapp3.1/UserInfo.txt&quot;;
  
              using (StreamReader reader = new StreamReader(fileName))
              {
                  Console.WriteLine(&quot;Please enter your username&quot;);
                  string line;
                  while ((line = reader.ReadLine()) != null)
                  {
                      int indexOfDelimiter = line.IndexOf('|');
                      string usernameFromFile = line.Substring(0, indexOfDelimiter);
                      string passwordFromFile = line.Substring(indexOfDelimiter + 1, line.Length - (indexOfDelimiter + 1));
                     
  
                      if (usernameFromFile.Equals(Username))
                      {
                          if (passwordFromFile.Equals(Password))
                          {
                              {
                              }
                          }
  
                      }
                  }
              }
          }
  </code></pre>