Ops Ops - 19 days ago 5
C# Question

Skip text in RichTextBox

I would skip the text in the field, if there is no text, but if this is to add text to the beginning and the end. I'm trying like this but it add text every line.

private void zmien(string a, string b)
{


{
if (richTextBox1.Text.Length > 0)
{
string[] lines = richTextBox1.Lines;
for (int i = 0; i < lines.Length; i++)
{
if (richTextBox1.Text.Length == 0)
{
for (int j = 0; i < lines.Length; i++)
lines[i] = Environment.NewLine;
}
else
lines[i] = a + lines[i] + b;
}
richTextBox1.Lines = lines;
//richTextBox1.SelectedText = "test" + lines;
}
}
}

mww mww
Answer

You can do that much simply as you think, try follow this code

 private void zmien(string a, string b)
    {
            if (richTextBox1.Text.Length > 0)
            {
                richTextBox1.Text = a+" "+richTextBox1.Text+" "+b;
            }
     }