C# string replacement question

c#, string

Solution

What about:

string listItem = 
      listBox1.SelectedItem.ToString().Substring(0, 
           listBox1.SelectedItem.ToString().IndexOf("~"));

Problem

Quick question. I have a listbox being populated from a directory listing. Each file contains its name and ~#####. I'm trying to read it all into a string and replace the ~#### with nothing. The #### could be digits from length 1-6 and could be anything from 0-9. Here's the code I'm using: ``` string listItem = (listBox1.SelectedItem.ToString().Replace("~*","")); ``` Example: ``` Here223~123 ---> Here Here224~2321 ----> Here ``` I can't replace any number because I need the numbers before the ~

Original source