String []lines = System.IO.File.ReadAllLines(path);
foreach (String line in lines)
{
line.Trim();
}
Obviously this doesn't work because String.Trim
returns the Trimmed version as a new String. And you can't do line = line.Trim()
. So is the only way to do this an old-school for
loop?
for(int i=0;i<lines.Length;++i)
{
lines[i] = lines[i].Trim();
}
Note I am restricted to Visual Studio 2005 i.e. .Net 2.0
lines.Select(l => l.Trim()).ToArray();
Alternatively, for .NET 2.0:
static IEnumerable<string> GetTrimmed(IEnumerable<string> array)
{
foreach (var s in array)
yield return s.Trim();
}
Used through:
lines = new List<string>(GetTrimmed(lines)).ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With