c# - Replace Text in ListBox
问题 How would I say, detect specific text in a listbox and replace it with specific text. Eg: private void timer1_Tick(object sender, EventArgs e) { if(listBox1.Text.Contains("Hi")) { // replace with Hello } } 回答1: In WinForms , you could do it like this: if(listBox1.Items.Cast<string>().Contains("Hi")){ //check if the Items has "Hi" string, case each item to string int a = listBox1.Items.IndexOf("Hi"); //get the index of "Hi" listBox1.Items.RemoveAt(a); //remove the element listBox1.Items.Insert