-1

I'm fairly new to programming and I had a hard time coming up with a title for my question. Let me try to explain it a bit better:

I have a for loop that iterates through a list of strings

for (int i = 0; i < StringList.Count; i++)
{               

}

The strings have a general pattern: The list starts with:

  1. String1
  2. String2
  3. String3
  4. String4
  5. String5

Then there is a possibility of StringT and StringB occuring randomly. After either string5 or the possible combinations of StringT or StringB occuring it goes back to a string1-5 and starts all over again. (Strings 1-5 are all slightly different but similar enough for filtering purposes). StringT and StringB both have identifying "features" I couldcheck in a if-statement

My Goal is:

Add the first 5 Strings to a TempString and check the possibillity of StringT or StringB being there. If they are there, add them to the TempString too. After That I'm adding the temp string to a list so list[0] would consist of (string1, string2, string3, string 4, string 5 and MAYBE StringT and or StringB)

Repeat the process after that until the loop is finished.

I tried it with a foreach loop and I tried solutions similar to this question: how to loop over generic List<T> and group per 3 items but none of them worked with the possibillity of random strings being there (at least for me)

Demokrit
  • 1
  • 6

1 Answers1

0

You can check the possibility of specific strings in a group of the list as below:

bool StringListEnded = false;    
            var resultGroup = new Dictionary<List<string>,bool>();
            foreach(List<string> list in StringListGroup){
                    bool StringTFound = false;
                    bool StringBFound = false;
                    foreach (string item in list)
                    {               
                       if(item == "someStringT")
                       {
                           StringTFound = true;
                       }
                       if(item == "someStringB")
                       {
                          StringBFound = true;
                       }
                    }
        //here you can save values in the dictionary against each list from the group and the possibility of occurring specific string using both flags for stringB and stringT
    if(StringTFound || StringBFound){
       resultGroup.Add(list,true);
    }
                }
Nomi Ali
  • 2,165
  • 3
  • 27
  • 48
  • I don't think that solves the Problem in the End I need a List with every position in the list containing (string1, string2, string3, string4, string5, maybe stringb, maybe stringt) The Problem is that string6 has the possibillity of being "string1" OR "stringB" OR "stringT". I know how to properly filter the strings out I just dont know how to group them if that makes sense – Demokrit Mar 27 '19 at 14:06