Edwin Torres
Edwin Torres

Reputation: 483

Replace text of items under a column in ListView

I need some help with some code I made to replace the text of an item in a listView.

I want to replace all items under column 4 of my listView. Heres an example string of an item in column 4: <span class="stat">0.58

Anyways here is what I wrote to replace the text in my listView but it isn't working:

foreach (ListViewItem i in listViewClickbank.Items)
{
    if (i.SubItems[3].Text.Contains("span"))
    {
        i.Text.Replace("<span class=", "");
    }
}

Upvotes: 3

Views: 1629

Answers (1)

Steven Doggart
Steven Doggart

Reputation: 43743

The String.Replace method returns the new string. It doesn't alter the original one. Also, you are changing the Text of the item (the first column), rather than the fourth column. Try this instead:

i.SubItems[3].Text = i.SubItems[3].Text.Replace("<span class=", "");

Upvotes: 5

Related Questions