-1

This is the method i have in a new class:

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 < Maps.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);
                        if (i == 0)
                        {
                            imagesSatelliteUrls.Add(t);
                            counter++;
                        }
                        if (i == 1)
                        {
                            imagesSatelliteUrls.Add(t);
                        }
                        position = endIndex + endTag.Length;
                        startIndex = Maps[i].IndexOf(startTag, position);

                    }
                    if (i >= 0)
                    {
                        imagesSatelliteUrls.Insert(0, "Group 1");
                    }
                    if (i == 1)
                    {
                        imagesSatelliteUrls.Insert(counter, "Group 2");
                    }
                    //imagesSatelliteUrls = imagesSatelliteUrls.OrderBy(q => q).ToList();
            }
        }

In the end imagesSatelliteUrls that is List contain for example 70 indexs inside. For example:

index[0] "Group 1"
index[1] some link here ... http...
index[2] some link here ... http...
.
.
.
index[30] some link here ... http...
.
.
.
.
index[45] "Group 2"
index[46] some link here ... http...
.
.
.
.
index[70] some link here ... http...

The variable Maps contain 7 indexs. So there will be 7 itertions/loops. I need somehow to make it automatic so it will add a new string like: "Group" + i For each group of links.

I can keep reseting the variable counter or use another int variable and count it in the if (i == 1 ) then in if (i == 2)

And then to make if ( i == 2) then imagesSatelliteUrls.Insert(newCounter, "Group 2");

But instead writing for each loop a new IF statement how can i make it all automatic ? So in each Maps itertion/loop it will add a new "Group" + i

The next thing is this line that im not using now:

imagesSatelliteUrls = imagesSatelliteUrls.OrderBy(q => q).ToList();

If i will use this line now it will put all the Groups in the beginning of the List. I need somehow that it will sort the indexs(links) for each Group. And not sort all the List imagesSatelliteUrls.

4

1 回答 1

2

如果您想为每个添加每个组i,那么您可以执行以下操作:

for (int i = 0; i < Maps.Count; i++) {
  //must place this at the very beginning of your loop
  imagesSatelliteUrls.Add("Group " + (i+1));
  //....
}
于 2013-10-28T19:12:21.290 回答