I am having a weird problem. I read a text file then I split it using \n as a delimiter. I noticed that the split lines contain ‘\r’ at the end. So I am trying to remove it, I tried doing so using String.Replace but without luck. Here is my code:
string fileOutput = File.ReadAllText(location);
SettingsManager.proxies.Clear();
foreach (string line in fileOutput.Split('\n'))
{
string cleanLine = line;
if (cleanLine.Contains("\r")) cleanLine.Replace("\r", "");
SettingsManager.proxies.Add(cleanLine);
}
EDIT: After staring at the code for 1 min, I found that I didn’t assign the replaced value to the original string.
cleanLine.Replace("\r",""); //assigns a value to nothing
I should have assigned cleanLine to cleanLine.Replace();
cleanLine = cleanLine.Replace("\r","");
I’m pretty sure running
fileOutput.Replace("\r","")would be better than calling a replace for each of the strings attained after the split. It might fix your problem as well.