I have the following data:
D:\toto\food\Cloture_49000ert1_10_01_2013.pdf
D:\toto\food\Cloture_856589_12_01_2013.pdf
D:\toto\food\Cloture_66rr5254_10_12_2012.pdf
How can I extract the date part? For example:
D:\toto\food\Cloture_49000ert1_10_01_2013.pdf --> 10_01_2013
D:\toto\food\Cloture_856589_12_01_2013.pdf --> 12_01_2013
D:\toto\food\Cloture_66rr5254_10_12_2012.pdf --> 10_12_2012
My idea is to use LastIndexOf(".pdf")
and then count 10 character backwards.
How can I solve this using substrings or another method?
Use Substring
in this case.
Retrieves a substring from this instance. The substring starts at a specified character position.
Try like this;
string s = "D:\\toto\\food\\Cloture_490001_10_01_2013.pdf";
string newstring = s.Substring(s.Length - 14, 10);
Console.WriteLine(newstring);
Here is a DEMO
.
You do not need to find index of .pdf
path.Substring(path.Length - 14, 10)
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