Use this:
var last = richTextBox1.Text.LastIndexOf(";");
if (last > 0)
{
richTextBox1.Text = richTextBox1.Text.Substring(0, last - 1);
var beforelast = richTextBox1.Text.LastIndexOf(";");
richTextBox1.Text = richTextBox1.Text.Substring(0, beforelast + 1);
}
else
{
richTextBox1.Text = "";
}
You did not specify the other scenarios(i.e, when the string does not contain ";") this code removes the string starting at ";" just before the last ";" to the last ";". It removes the last semicolon and texts after that, then finds the new last ";". finally removes the text after this ";"