C#根据网址抓区目录和文件名的两个函数
我学这个软件开始都思考这个问题了.今天终于完善了这个代码.高兴得很 2006-10-20 ,难道是晚上工作效率更高精神更集中的原因么?哈哈
public void GetUrlFolerName(string strHtmlPagePath)
{
//抓取网址字符串中的文件目录
int at = 0;
int start = 0;
int notei=0;
int endi=0;
int[] myIntArray = new int[10];
string NewFolderName;
while((start < strHtmlPagePath.Length) && (at > -1))
{
at = strHtmlPagePath.IndexOf('/', start);
if (at == -1) break;
myIntArray[notei]=at;
start = at+1;
notei = notei+1;
endi=at;
}
for(int i=0;i<notei;i++)
{
//lstFiles.Items.Add(myIntArray[i]);
if(myIntArray[i]>0)
{
if (myIntArray[i+1]>0)
{
NewFolderName=strHtmlPagePath.Substring(myIntArray[i]+1,myIntArray[i+1]-myIntArray[i]-1);
lstFiles.Items.Add(NewFolderName);
}
}
}
}
public void GetUrlFileName(string strHtmlPagePath)
{
//抓取网址字符串中的文件名称
int at = 0;
int start = 0;
int notei=0;
int endi=0;
int[] myIntArray = new int[10];
while((start < strHtmlPagePath.Length) && (at > -1))
{
at = strHtmlPagePath.IndexOf('/', start);
if (at == -1) break;
myIntArray[notei]=at;
start = at+1;
notei = notei+1;
endi=at;
}
for(int i=0;i<notei;i++)
{
//lstFiles.Items.Add(myIntArray[i]);
if(myIntArray[i]>0)
{
if (myIntArray[i+1]==0)
{
string NewFileName=strHtmlPagePath.Substring(myIntArray[i]+1,strHtmlPagePath.Length-myIntArray[i]-1);
//lstFiles.Items.Add(NewFileName);
txtSaveFileName.Text=NewFileName.ToLower();
}
}
}
}