C# 如何循环每个地图以从中提取图像链接?

C# 如何循环每个地图以从中提取图像链接?,c#,winforms,C#,Winforms,在表格1中,我有以下代码: using (WebClient client = new WebClient()) { client.DownloadFile("http://www.sat24.com/foreloop.aspx?type=0&continent=europa#", localFilename + "Sat24_Temperature_Europe.html"); client.Dow

在表格1中,我有以下代码:

using (WebClient client = new WebClient())
            {
                client.DownloadFile("http://www.sat24.com/foreloop.aspx?type=0&continent=europa#", localFilename + "Sat24_Temperature_Europe.html");
                client.DownloadFile("http://www.sat24.com/foreloop.aspx?type=1&continent=europa#", localFilename + "Sat24_Rain_Europe.html");
                client.DownloadFile("http://www.sat24.com/foreloop.aspx?type=2&continent=europa#", localFilename + "Sat24_Wind_europe.html");
                client.DownloadFile("http://www.sat24.com/foreloop.aspx?type=3&continent=europa#", localFilename + "Sat24_Lightnings_Europe.html");
                client.DownloadFile("http://www.sat24.com/foreloop.aspx?type=4&continent=europa#", localFilename + "Sat24_Cloudtypes_Europe.html");
                client.DownloadFile("http://www.sat24.com/?ir=true&ra=true&li=false", localFilename + "Sat24_Cloudsheight_Europe.html");
                client.DownloadFile("http://www.sat24.com/en/eu?ir=true", localFilename + "Sat24_Satellite_Europe.html");
            }
            MapsToRead = Directory.GetFiles(localFilename, "*.*");
            for (int i = 0; i < MapsToRead.Length; i++)
            {
                string s = File.ReadAllText(MapsToRead[i]);
                Maps.Add(s);
            }
            StartTags = new List<string>();
            StartTags.Add("image2.ashx"); 
            StartTags.Add("http://www.niederschlagsradar.de/images.aspx"); 
            LastTags = new List<string>();
            LastTags.Add("ra=true");
            LastTags.Add("cultuur=en-GB&continent=europa");
            LastTags.Add("ir=true");
使用(WebClient=newWebClient())
{
client.DownloadFile(“http://www.sat24.com/foreloop.aspx?type=0&continent=europa#,localFilename+“Sat24_Temperature_european.html”);
client.DownloadFile(“http://www.sat24.com/foreloop.aspx?type=1&continent=europa#,localFilename+“Sat24_Rain_european.html”);
client.DownloadFile(“http://www.sat24.com/foreloop.aspx?type=2&continent=europa#,localFilename+“Sat24_Wind_european.html”);
client.DownloadFile(“http://www.sat24.com/foreloop.aspx?type=3&continent=europa#,localFilename+“Sat24_lightings_european.html”);
client.DownloadFile(“http://www.sat24.com/foreloop.aspx?type=4&continent=europa#,localFilename+“Sat24_Cloudtypes_Europe.html”);
client.DownloadFile(“http://www.sat24.com/?ir=true&ra=true&li=false,localFilename+“Sat24_cloudsheigh_european.html”);
client.DownloadFile(“http://www.sat24.com/en/eu?ir=true,localFilename+“Sat24_Satellite_european.html”);
}
MapsToRead=Directory.GetFiles(localFilename,*.*);
for(int i=0;i
由于html文件中的标记在大多数情况下都是相同的,所以我只在StartTags和LastTags中添加了所需的标记

现在在新课程中,我有一个方法:

public ExtractImages(List<string> FirstTags, List<string> LastTags, List<string> Maps, string LocalFileDir, string UrlsDir)
        {
            localdir = LocalFileDir;
            counter = 0;
            imagesSatelliteUrls = new List<string>();
            imagesRainUrls = new List<string>();
            int startIndex = 0;
            int endIndex = 0;
            int position = 0;
            for (int i = 0; i < FirstTags.Count; i++)
            {
                string startTag = FirstTags[i];
                string endTag = LastTags[i];
                startIndex = Maps[i].IndexOf(startTag);
                while (startIndex > 0)
                {

                    endIndex = Maps[i].IndexOf(endTag, startIndex);
                    if (endIndex == -1)
                    {
                        break;
                    }
                    string t = Maps[i].Substring(startIndex, endIndex - startIndex + endTag.Length);
                    imagesSatelliteUrls.Add(t);
for (int i = 0; i < FirstTags.Count; i++)
public ExtractImages(列出FirstTags、列出LastTags、列出映射、字符串LocalFileDir、字符串UrlsDir)
{
localdir=LocalFileDir;
计数器=0;
imagesSatelliteUrls=新列表();
imagesRainUrls=新列表();
int startIndex=0;
int-endIndex=0;
int位置=0;
for(int i=0;i0)
{
endIndex=Maps[i].IndexOf(endTag,startIndex);
如果(endIndex=-1)
{
打破
}
字符串t=Maps[i]。子字符串(startIndex,endIndex-startIndex+endTag.Length);
imagesSatelliteUrls.Add(t);
在对Form1中的标记进行更改之前,我只向每个标记列表添加了7次相同的标记,因为列表映射包含7个索引。 然后在新通话中,当我在做:

public ExtractImages(List<string> FirstTags, List<string> LastTags, List<string> Maps, string LocalFileDir, string UrlsDir)
        {
            localdir = LocalFileDir;
            counter = 0;
            imagesSatelliteUrls = new List<string>();
            imagesRainUrls = new List<string>();
            int startIndex = 0;
            int endIndex = 0;
            int position = 0;
            for (int i = 0; i < FirstTags.Count; i++)
            {
                string startTag = FirstTags[i];
                string endTag = LastTags[i];
                startIndex = Maps[i].IndexOf(startTag);
                while (startIndex > 0)
                {

                    endIndex = Maps[i].IndexOf(endTag, startIndex);
                    if (endIndex == -1)
                    {
                        break;
                    }
                    string t = Maps[i].Substring(startIndex, endIndex - startIndex + endTag.Length);
                    imagesSatelliteUrls.Add(t);
for (int i = 0; i < FirstTags.Count; i++)
for(int i=0;i
所以FirstTags包含7个索引,LastTags包含7个索引,Maps包含7个索引。 但是现在在更改之后,FirstTags包含2个索引,LastTags包含3个索引。 地图包含7个索引

我现在如何执行FOR循环,以便它将遍历所有7个贴图,并为每个贴图使用标记

例如,对于地图[0],起始标记为“image2.ashx” 但对于地图[1]和[2]以及[4][5]和[6],它们的标签是相同的:“

最后的标签也是一样

以下是Form1中的标签现在的工作方式:

StartTags = new List<string>();
StartTags.Add("image2.ashx"); 
StartTags.Add("http://www.niederschlagsradar.de/images.aspx"); 
LastTags = new List<string>();
LastTags.Add("ra=true");
LastTags.Add("cultuur=en-GB&continent=europa");
LastTags.Add("ir=true");
StartTags=newlist();
StartTags.Add(“image2.ashx”);
开始标记。添加(“http://www.niederschlagsradar.de/images.aspx"); 
LastTags=新列表();
添加(“ra=true”);
添加(“cultuur=en GB,大陆=europa”);
添加(“ir=true”);
在我更改之前,旧版本是这样的:

StartTags = new List<string>();
            StartTags.Add("image2.ashx"); 
            StartTags.Add("http://www.niederschlagsradar.de/images.aspx"); // Cloudstypes forecast map of europe
            StartTags.Add("http://www.niederschlagsradar.de/images.aspx"); // Lightnings forecast map of europe
            StartTags.Add("image2.ashx"); // Satellite map of europe
            StartTags.Add("http://www.niederschlagsradar.de/images.aspx"); // Rain forecast map of europe
            StartTags.Add("http://www.niederschlagsradar.de/images.aspx"); // Temperature forecast map of europe
            StartTags.Add("http://www.niederschlagsradar.de/images.aspx"); // Wind forecast map of europe
            LastTags = new List<string>();
            LastTags.Add("ra=true"); // Cloudsheight forecast map of europe
            LastTags.Add("cultuur=en-GB&continent=europa"); // Cloudstypes forecast map of europe
            LastTags.Add("cultuur=en-GB&continent=europa"); // Lightnings forecast map of europe
            LastTags.Add("ir=true"); // Satellite map of europe
            LastTags.Add("cultuur=en-GB&continent=europa"); // Rain forecast map of europe
            LastTags.Add("cultuur=en-GB&continent=europa"); // Temperature forecast map of europe
            LastTags.Add("cultuur=en-GB&continent=europa"); // Wind forecast map of europe
StartTags=newlist();
StartTags.Add(“image2.ashx”);
开始标记。添加(“http://www.niederschlagsradar.de/images.aspx“”;//欧洲云彩预测图
开始标记。添加(“http://www.niederschlagsradar.de/images.aspx“”;//欧洲闪电预报图
StartTags.Add(“image2.ashx”);//欧洲卫星地图
开始标记。添加(“http://www.niederschlagsradar.de/images.aspx“”;//欧洲降雨预报图
开始标记。添加(“http://www.niederschlagsradar.de/images.aspx“”;//欧洲气温预报图
开始标记。添加(“http://www.niederschlagsradar.de/images.aspx“”;//欧洲风预报图
LastTags=新列表();
LastTags.Add(“ra=true”);//欧洲云量预测图
LastTags.Add(“cultuur=en-GB&containment=europa”);//欧洲云彩预测图
LastTags.Add(“cultuur=en-GB&containment=europa”);//欧洲闪电预报地图
LastTags.Add(“ir=true”);//欧洲卫星地图
LastTags.Add(“cultuur=en-GB&containment=europa”);//欧洲降雨预报图
LastTags.Add(“cultuur=en-GB&containment=europa”);//欧洲温度预测图
LastTags.Add(“cultuur=en-GB&containment=europa”);//欧洲风预报图

由于其中的一些标记大部分是相同的,所以我对其进行了更改,但现在如何在新类中创建FOR循环,因为每个列表都有另外数量的索引?

您不需要用这种方式压缩列表。因为
.NET
中的字符串是不可变的,并且它们由编译器优化。All相同的字符串对象将指向存储字符串值的相同内存。旧的
列表
指向存储字符串值的内存的引用当然会比新的压缩对象多。但是这非常少。如果要避免重复用于向列表添加项的代码