日期:2014-05-19  浏览次数:20881 次

截取某个字符串的问题。
FileSource   =   "H:\\资料\\库\\哲学名字术语2.txt "
从这个串截取“哲学名字术语”几个字符,就是 "\\ "   和“.”之间的字符。

------解决方案--------------------
LastIndexOf( ". ")
LastIndexOf( "\\ ")
------解决方案--------------------
try


string FileSource = "H:\\资料\\库\\哲学名字术语2.txt ";
string resultStr = " ";
Match m = Regex.Match(FileSource, @ "(? <=\\)[^\\]*?(?=\.) ");
if(m.Success)
{
resultStr = m.Value;
}
------解决方案--------------------
or try

string FileSource = "H:\\资料\\库\\哲学名字术语2.txt ";
string resultStr = FileSource.Substring(FileSource.LastIndexOf( "\\ ")+1,FileSource.LastIndexOf( ". ")-FileSource.LastIndexOf( "\\ ")-1);