title: C# Remove file extension from string list
body: <p>What my program does is basically it lists file names (including it's extension) from a directory into a listbox. It then has a sorting function which sorts the list strings into alphabetical order.</p>
  
  <p>Lastly it has a binary search function that allows the users to input any string which the program will then compare and display the matched results into a listbox.</p>
  
  <p>Now, all these functions work perfectly however I can't seem to remove the extension off of a file name after a search.</p>
  
  <p>For example in the scanning and sorting part it lists the file names as: filename.mp3</p>
  
  <p>Now, what I want it do when the searching button is clicked is to remove the file extension and display just the filename.</p>
  
  <pre><code>    private void buttonSearch_Click(object sender, RoutedEventArgs e)
      {
  
          listBox1.Items.Clear();
  
          string searchString = textBoxSearchPath.Text;
  
  
          int index = BinarySearch(list1, 0, list1.Count, searchString);
  
          for (int n = index; n &lt; list1.Count; n++)
          {
              //Removes file extension from last decimal point ''not working''
              int i = list1[n].LastIndexOf(".");
              if (i &gt; 0)
                  list1[n].Substring(0, i);
  
              // Adds items to list
              if (list1[n].IndexOf(searchString, StringComparison.OrdinalIgnoreCase) != 0) break; 
              listBox1.Items.Add(list1[n]);
          }
          MessageBox.Show("Done");
      }
  </code></pre>