The WinForms TextBox has a 'Lines Property that returns a readonly array of strings. Interestingly, the 'Lines Property, as a whole, can be assigned to.
To modify any one line of Text in a TextBox's Lines array:
private void ModifyLine(TextBox targetTB, int lineToChange, string newLineContent)
{
if (lineToChange > targetTB.Lines.Length - 1)
throw new ArgumentOutOfRangeException
(
"lineToChange",
"invalid index to Lines collection of TextBox: " + targetTB.Name
);
string[] lineAry = new string[targetTB.Lines.Length];
targetTB.Lines.CopyTo(lineAry, 0);
lineAry[lineToChange] = newLineContent;
targetTB.Lines = lineAry;
}
A sample of a call to 'ModifyLine:
ModifyLine(textBox1, 2, "modified line 3");