我有以下数据:
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如何提取日期部分?例如:
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我的想法是使用LastIndexOf(".pdf"),然后倒数10个字符。
如何使用子字符串或其他方法解决此问题?
发布于 2013-01-15 20:53:58
在本例中使用。
从此实例中检索子字符串。子字符串从指定的字符位置开始。
试着这样做;
string s = "D:\\toto\\food\\Cloture_490001_10_01_2013.pdf";
string newstring = s.Substring(s.Length - 14, 10);
Console.WriteLine(newstring);这是一个。
发布于 2013-01-15 20:52:25
您不需要查找.pdf的索引
path.Substring(path.Length - 14, 10)发布于 2013-01-15 20:54:33
我会用Regex来做这件事。
^[\w:\\]+cloture_(\d+)_([\d_]+).pdf$将与第二组中的日期匹配。
https://stackoverflow.com/questions/14338134
复制相似问题