我用C#读取出了文件地址和文件名称,现在,我要截取其中的一段,怎么做,我读取出的文件代码是这样的:
StringBuilder sb = new StringBuilder(); nn = new FHDB.Model.NW_NEWS();
string all = PBO.EidFile.ReadFile(path, "gb2312");
其中的PBO.EidFile.ReadFile是一个读取文件的方法,我读取出来的文件地址和名称如下:E:/工作/重要《新华网所有页面》/house/2010-08/02/content_20501101.htm,我要判断文件content_20501101后面有没有_,有,就说明有子文件,然后要将页面的内容截取出来
StringBuilder sb = new StringBuilder(); nn = new FHDB.Model.NW_NEWS();
string all = PBO.EidFile.ReadFile(path, "gb2312");
其中的PBO.EidFile.ReadFile是一个读取文件的方法,我读取出来的文件地址和名称如下:E:/工作/重要《新华网所有页面》/house/2010-08/02/content_20501101.htm,我要判断文件content_20501101后面有没有_,有,就说明有子文件,然后要将页面的内容截取出来
string str = "E:/工作/重要《新华网所有页面》/house/2010-08/02/content_20501101.htm";
str=str.Substring(str.LastIndexOf('/') + 1);
string htm;
if (str.IndexOf('_') > -1)
{
htm = str.Substring(str.LastIndexOf('_') + 1);
//存在
}
else
{
//不存在
}
你的意思是content_20501101后面还可能会。。content_20501101_123123?
如果是一个文件,那么就读取文件了。
不要判断文件名了吧。if(System.IO.File.Exists("C:\\test.htm"))
{
MessageBox.Show("文件存在,请处理");
}
if(Path.GetFileName(path).IndexOf('_')==-1)
{
//不存在
.....
}else
{
//存在
......
}
string str = "E:/工作/重要《新华网所有页面》/house/2010-08/02/content_20501101.htm";
if (str.Contains("content_"))
{
Console.WriteLine("yes");
}
else
{
Console.WriteLine("no");
}