Try to implement update some part of string in file
Currently make some code
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(filePath);
string[] line = sr.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
List<string> lines = new List<string>();
string eventName = ','+eventNameUpdateTextBox.Text.ToString()+',';
foreach (var l in line)
{
if (l.Contains(eventName))
{
int start = l.IndexOf(eventName);
l.Remove(start, eventName.Length);
l.Insert(start, newNameTextBox.Text.ToString());
lines.Add(l);
}
else
{
lines.Add(l);
}
}
string toCsvOutput = string.Join(Environment.NewLine, lines.ToArray());
But result - same file like and before.
Try to debug it, as result see, that function
l.Insert(start, newNameTextBox.Text.ToString());
do not change string and return same string as at the beginning/ why did it happen? Where am I wrong?