Extract dates from filename(C#3.0)
- by Newbie
I have a situation where I need to extract dates from the file names whose general pattern is [filename_]YYYYMMDD[.fileExtension]
e.g. "xxx_20100326.xls" or x2v_20100326.csv
The below program does the work
//Number of charecter in the substring is set to 8
//since the length of YYYYMMDD is 8
public static string ExtractDatesFromFileNames(string fileName)
{
return fileName.Substring(fileName.IndexOf("_") + 1, 8);
}
Is there any better option of achieving the same?
I am basically looking for standard practice.
I am using C#3.0 and dotnet framework 3.5
Thanks