Basically our problem: We cannot replace the string as follows: 10003 * But we can replace the string as follows: 10003
we want to replace the part of the line that looks like this: 10003 * This is our code:
string text = sr2.ReadToEnd(); sr2.Close(); while (loop != lstTxt.Items.Count) { string SelectedItem = lstTxt.SelectedItem.ToString() + "*"; text = text.Replace(SelectedItem, "tietze111"); if (lstTxt.SelectedIndex < lstTxt.Items.Count - 1) lstTxt.SelectedIndex++; loop++; } sw2.Write(text);
But that will not work. When we leave * in the replacement part, it works. But we must also replace *. Do you know what we need to change?
It works when we use this:
string text = sr2.ReadToEnd(); sr2.Close(); while (loop != lstTxt.Items.Count) { string SelectedItem = lstTxt.SelectedItem.ToString(); // changed text = text.Replace(SelectedItem, "tietze111"); if (lstTxt.SelectedIndex < lstTxt.Items.Count - 1) lstTxt.SelectedIndex++; loop++; } sw2.Write(text);
- using (var sr2 = new StreamReader (Application.StartupPath + @ "\ website \ Dehler 22 ET.htm", Encoding.Default)) {
using (var sw2 = new StreamWriter(tempFile, true, Encoding.Default))
We use this because the file is still in ASCII. Perhaps this is the problem. How do we solve this?
source share