I have a textbox that holds file content. I have a button that when it is pressed, it deletes a line based on a string. Here is the code:
private void deleteModuleButton_Click(object sender, EventArgs e)
{
String newText = String.Empty;
List<String> lines = fileContentTextBox.Text.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();
lines.RemoveAll(str => str.Contains(deleteModuleComboBox.Text));
lines.ForEach(str => newText += str + Environment.NewLine);
fileContentTextBox.Text = newText;
}
private void deleteModuleButton_Click(object sender, EventArgs e)
{
String newText = String.Empty;
List<String> lines = fileContentTextBox.Text.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();
lines.RemoveAll(str => str.Contains(deleteModuleComboBox.Text));
newText = string.Join(Environment.NewLine, lines);
fileContentTextBox.Text = newText;
}
Replace
lines.ForEach(str => newText += str + Environment.NewLine);
with
newText = string.Join(Environment.NewLine , lines);