-1

I have a problem with String.Replace method. It is not working for buttonclick events.

i use this code

private void button4_Click(object sender, EventArgs e)
{
       textBox3.Text.Replace("apple","");
}

Please see the image

When I press clear button it doesn't remove "apple" words

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
user3398379
  • 83
  • 1
  • 8
  • `testBox3.Text = textBox3.Text.Replace("apple","");` simple fix would have been to read up on the string.Replace() function – MethodMan Dec 19 '17 at 02:30
  • It is well knows fact that [C# string replace does not work](https://www.bing.com/search?q=c%23+string+replace+does+not+work). – Alexei Levenkov Dec 19 '17 at 02:33

1 Answers1

2

The replace function does not change the control, it returns a new string.

If textBox3 says "applebananacherry"

String text = textBox3.Text.Replace("apple","");

would leave text with "bananacherry"

What you need is

textBox3.Text = textBox3.Text.Replace("apple", "");
NeedsAnswers
  • 169
  • 5