for (int i = 0; i < newText.Count; i++)
{
for (int x = 0; x < WordsList.words.Length; x++)
{
lineToPost = newText[i];
if (!lineToPost.Contains(WordsList.words[x]))
{
newText.Remove(lineToPost);
}
}
}
words is a type array string[] newText is List
I want to remove from newText lines that not contain any word from words. In a new class this is how i built the array words:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ScrollLabelTest
{
class WordsList
{
public static string[] words =
{ "testing", "world", "ראשוני", "new", "hello", "test" };
}
}
This is how the newText List look like:
The first line is a text line then a line with date and time then empty line/space. Then again text line date and time line and empty line/space.
What i want to do is to keep this newText format and remove any text line/s that are not contain any word from words.
Tried to do it like this:
newText.Remove(lineToPost);
But that will remove any line that is not with any word. I want to remove only text line/s that not contain any word. The way im doing now will give after few itertions exception out of index...on: lineToPost = newText[i]; since it's removing any line from the List.
The main goal:
To remove/filter any text line that any of the words not exist in this line.
To keep the List newText format as it is in the original (screenshot ).
In the screenshot:
Index 0 is text line Index 1 is a date time line Index 2 is empty/space line
If in the line in index 0 the line not contain any of the words remove this line and remove also line index 1 and index 2.
Next if in index 3 none of the words exist remove index 3 4 and 5.
In the end the format of newText should be the same as it is in the screenshot. Just without the lines that didnt have the words.