Search code examples
c#stringtrim

How can you trimend of textbox text from another textbox text


I have two textbox's textbox1 (read/write) & textbox2 (read only), textbox1 is where you enter text at which point you press a button to pass that text into textbox2 (textbox2 continually concatenates the text from textbox1). I have a second button that I want to press to remove the text from textbox2 that is still in textbox1. Can anyone suggest how to do this?

I was thinking;

string one = textbox1.text;
string two = textbox2.text;
string newTwo = two.trimend( value of string 'one' needs to be removed );
textbox2.text = newTwo;

textbox1;
world

textbox2;
hello world

I know this sounds odd but it's a bit of a work around for an algebra calculator.


Solution

  • If (textbox2.Text.EndsWith(textbox1.Text))
        textbox2.Text = textbox2.Text.Substring(0, textbox2.Text.Length - textbox1.Text.Length);