title: How can I parse a file name from string using IndexOf and Substring?
body: <pre><code>private void ParseFilesNames()
  {
      using (WebClient client = new WebClient())
      {
          try
          {
              for (int i = 0; i &lt; 15; i++)
              {
                  string urltoparse = "mysite.com/gallery/albums/from_old_gallery/" + i;
                  string s = client.DownloadString(urltoparse);
                  int index = -1;
                  while (true)
                  {
                      string firstTag = "HREF=";
                      string secondtag = "&gt;";
                      index = s.IndexOf(firstTag, 0);
                      int endIndex = s.IndexOf(secondtag, index);
                      if (index &lt; 0)
                      {
                          break;
                      }
                      else
                      {
                          string filename = s.Substring(index + firstTag.Length, endIndex - index - firstTag.Length);
                      }
                  }
              }
          }
          catch (Exception err)
          {
          }
      }
  }
  </code></pre>
  
  <p>The problem is with the Substring. index + firstTag.Length, endIndex - index - firstTag.Length
  This is wrong.</p>
  
  <p>What I need to get is the string between: <code>HREF="</code> and <code>"&gt;</code></p>
  
  <p>The whole string looks like: <code>HREF="myimage.jpg"&gt;</code>
  I need to get only "myimage.jpg"</p>
  
  <p>And sometimes it can be "myimage465454.jpg" so in any case I need to get only the file name. Only "myimage465454.jpg".</p>
  
  <p>What should I change in the substring?</p>