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
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top