Hi Sunny Kumar and Vulpes
Usually, I do get useful solution when you both reply my questions, then it would be nice if
you reply my question also ![]()
For the below code, how to ignore reading white spaces especially when each row in my text file begins with space.
if (Files.Lenght > 0)
foreach (string file in files)
{
try
{
var list = new List
using (var reader = new StreamReader(file))
{
for (int i = 0; i < 10; i++)
{
list.Add(reader.ReadLine());
}
}
string newFileName = string.Concat(Path.GetFileNameWithoutExtension(file), "-",list[3], "-", list[8],"-",list[9],"-",list[10], "txt");
newFileName=Regex.Replace(newFileName, @"\*", "X");
newFileName = Regex.Replace(newFileName, @"\/", "");
string newFile = string.Concat(outputDirectory,"\\",newFileName,".txt");
File.Copy(file, newFile);

VulpesRank #55 · 29.2K reputationPosted Sep 11, 2013, 4:35 AM EDT
If you only want to ignore leading or trailing whitespace, then use the Trim() method rather than Replace().
If you want to skip lines which are empty or only contain whitespace, then you will need to use code such as the following:
Pavan RamamurthyRank #1,682 · 906 reputationPosted Sep 10, 2013, 10:45 PM EDT
Suthish NairRank #92 · 22.8K reputationPosted Sep 11, 2013, 5:00 AM EDT
using (StreamReader sr = new StreamReader(@"TextFile1.txt"))
{
Console.WriteLine(sr.ReadLine().Trim());
//Console.WriteLine(sr.ReadToEnd().Trim());
}
Console.ReadLine();
Rohit Singh Gurjar27 reputationPosted Jan 11, 2018, 12:02 AM EST