1
Currently I inform in variable stringantiga
the exact value to find and replace it.
Is there any way to substitute for the line number instead of the exact value of stringantiga
?
string arquivo = ConfigurationSettings.AppSettings["Caminho"].ToString();
string stringbusca = "MaxChannelInUse";
string stringantiga = "MaxChannelInUse=80";
string stringnova = "MaxChannelInUse=90000";
StreamReader sr = new StreamReader(arquivo);
StringBuilder sb = new StringBuilder();
while (!sr.EndOfStream)
{
string s = sr.ReadLine();
if (s.IndexOf(stringbusca) > -1)
{
s = s.Replace(stringantiga, stringnova);
}
sb.AppendLine(s);
}
sr.Close();
StreamWriter sw = new StreamWriter(arquivo);
sw.Write(sb);
sw.Close();
For example, if by chance someone enters my text file and deletes one of the lines. Is there any other way to find that specific value in my example (stringantiga= "Maxchannelinuse") ?
– Gabriel Sant'Ana
@Gabrielsant'Ana Certainly not.
– Jéf Bueno