C#substring在中间

use*_*628 4 c# string substring

我有以下数据:

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
Run Code Online (Sandbox Code Playgroud)

如何提取日期部分?例如:

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
Run Code Online (Sandbox Code Playgroud)

我的想法是使用LastIndexOf(".pdf") 然后倒数10个字符.

如何使用子串或其他方法解决这个问题?

Son*_*nül 6

Substring在这种情况下使用.

从此实例中检索子字符串.子字符串从指定的字符位置开始.

试试这样;

string s = "D:\\toto\\food\\Cloture_490001_10_01_2013.pdf";
string newstring = s.Substring(s.Length - 14, 10);
Console.WriteLine(newstring);
Run Code Online (Sandbox Code Playgroud)

这是一个DEMO.