r/programminghelp • • Feb 22 '20

C# Wont Replace Correctly

Post image
8 Upvotes

5 comments sorted by

3

u/jakbrtz Feb 22 '20

I'm not sure what you're trying to achieve, but I think it's useful that you know that you can chain the replace methods like this:

OutputBox.Text = OutputBox.Text.Replace("a","").Replace("b","");

3

u/AccHasBeentaken Feb 22 '20

Thanks! It worked.

1

u/jakbrtz Feb 22 '20

Great!

When trying to fix these types of problems, I find it useful to see what happens when you use larger inputs. For example, set OutputBox.Text to "lettersabcde" and it will change to "lettersbcdelettersacde". That might give you a better understanding of what is happening in your code.

1

u/AccHasBeentaken Feb 22 '20

Thanks, I'll try that.