I'm trying to remplace space for pipes in a text file but if there are 4 or more spaces. my code till now is:
string MyNewFile;
using (StreamWriter sWriter = new StreamWriter(MyNewFile, false, encoding, 1))
{
using (StreamReader sReplaceReader = new StreamReader(myFile))
{
string line, textLine = "";
while ((line = sReplaceReader.ReadLine()) != null)
{
if (line.Contains(" ")>=4 )//if contains 4 or more spaces
{
textLine = line.Replace(" ", "|");
}
sWriter.WriteLine(textLine);
}
}
}
My idea is to get the number of spaces by a parameter in a method but, I dont know how to put something like line.Replace(4.space or 4 char.IsWhiteSpace(), separator). I hope you have explained me well