If ListBox's items are not bound with data source, you can change the text of items in single loop.
See C# code (LinqPad):
void Main()
{
MyForm mf = new MyForm();
}
public class MyForm: Form
{
public MyForm()
{
this.Size = new Size(600, 340);
this.Text = "MyForm";
InitializeControls();
this.Show();
}
private void InitializeControls()
{
ListBox1 = new ListBox(){Location = new Point(10,10), Size = new Size(150, 280), Anchor = (AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom)};
for(int i =1; i<=20; i++)
ListBox1.Items.Add($"Item_{i}");
Button1 = new Button(){Location = new Point(180,10), Size = new Size(120, 24), Anchor = (AnchorStyles.Left | AnchorStyles.Top), Text = "Change text!"};
Button1.Click += Button1_Click;
this.Controls.Add(ListBox1);
this.Controls.Add(Button1);
}
private void Button1_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
string btnText = btn.Text == "Change text!" ? "Change again ;)" : "Change text!";
char splitOn = btn.Text == "Change text!" ? '_' : '@';
string replacement = btn.Text == "Change text!" ? "@" : "_";
for(int i=0; i<ListBox1.Items.Count; i++)
{
object item = ListBox1.Items[i];
string[] parts = item.ToString().Split(splitOn);
string newText = parts[0] + replacement + parts[1];
ListBox1.Items[i] = newText;
btn.Text = btnText;
}
}
private ListBox ListBox1;
private Button Button1;
}