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);
VulpesPosted Sep 11, 2013, 8:35 AM
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:
Rohit Singh GurjarPosted Jan 11, 2018, 5:02 AM
Suthish NairPosted Sep 11, 2013, 9:00 AM
using (StreamReader sr = new StreamReader(@"TextFile1.txt"))
{
Console.WriteLine(sr.ReadLine().Trim());
//Console.WriteLine(sr.ReadToEnd().Trim());
}
Console.ReadLine();
Pavan RamamurthyPosted Sep 11, 2013, 2:45 AM