richTextBox.Text.Remove()

  • Thread starter Thread starter kangoo
  • Start date Start date
K

kangoo

Hi,

I'm trying to remove the last charater in a richTextBox. I though
richTextBox.Text.Remove(richTextBox.Text.length-1, 1); would work, but
it does nothing
(eg richTextBox.Text += "some new text"; works)

Thanks for your attention & solutions
 
kangoo said:
Hi,

I'm trying to remove the last charater in a richTextBox. I though
richTextBox.Text.Remove(richTextBox.Text.length-1, 1); would work, but
it does nothing
(eg richTextBox.Text += "some new text"; works)

Thanks for your attention & solutions
richTextBox.Text = richTextBox.Text.Remove(richTextBox.Text.Length - 1, 1).

Notice assignment. It should always be when you use strings.
 
kangoo said:
Hi,

I'm trying to remove the last charater in a richTextBox. I though
richTextBox.Text.Remove(richTextBox.Text.length-1, 1); would work, but
it does nothing
(eg richTextBox.Text += "some new text"; works)

Thanks for your attention & solutions

string text = richTextBox.Text;
richTextBox.Text = text.Remove(text.Length - 1, 1);

As for the [richTextBox.Text += "some new text";] statement, using
RichTextBox.AppendText(string) would probably be more efficient there.
 
Dmitry said:
richTextBox.Text = richTextBox.Text.Remove(richTextBox.Text.Length - 1, 1).

Notice assignment. It should always be when you use strings.

thx u and C# learner
didn't know that
:)
 
Back
Top