C# 如何过滤和删除不带';是否不包含指定的单词?

C# 如何过滤和删除不带';是否不包含指定的单词?,c#,winforms,C#,Winforms,这是目前的方法: private void WordsFilter(List<string> newText) { for (int i = 0; i < newText.Count; i++) { for (int x = 0; x < WordsList.words.Length; x++) { lineToPost = ScrollLabel._lines[i]; if

这是目前的方法:

private void WordsFilter(List<string> newText)
{
    for (int i = 0; i < newText.Count; i++)
    {
        for (int x = 0; x < WordsList.words.Length; x++)
        {
            lineToPost = ScrollLabel._lines[i];
            if (!lineToPost.Contains(WordsList.words[x]))
            {
                newText.Remove(lineToPost);
            }
        }
    }
}
private void words过滤器(列出新文本)
{
for(int i=0;i
newText是List,WorldsList.words是string[]

我在newText中的行上循环,在单词上循环,我想用这种方式检查:

在newText中循环所有单词的第一行,如果此行中没有任何单词,请删除当前行和其后的下一行。 例如,在newText中,如果索引0中的行是:Hello everyone 索引1中的行是:创建于2002年12月3日 然后删除索引0和索引1

索引2是空的,就像一个空格空行,所以不要删除它

然后索引3循环所有单词,如果索引3中的行中存在非OE单词,则删除索引3和索引4

等等

我怎么做呢?

。我试图不更改代码的逻辑:

using System;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        List<string> list = new List<string>() {"truc", "I love toto", "next", "chocolate", "tata tata", "", "something"};
        WordsFilter(list);
    }

    private static void WordsFilter(List<string> newText)
    {
        string[] WordsList = new string[] { "toto", "tata" };

        for (int i = 0; i < newText.Count; i++)
        {
            for (int x = 0; x < WordsList.Length; x++)
            {
                if (newText[i].Contains(WordsList[x]))
                {
                    newText.RemoveAt(i);
                    if (i + 1 < newText.Count)
                        newText.RemoveAt(i);
                }
            }
        }

        // print
        foreach(var item in newText)
        {
            Console.WriteLine(item);
        }
    }
}
使用系统;
使用System.Collections.Generic;
公共课程
{
公共静态void Main()
{
List List=new List(){“truc”,“我爱托托”,“next”,“巧克力”,“塔塔塔塔”,“某物”};
字过滤器(列表);
}
私有静态无效字过滤器(列出新文本)
{
string[]WordsList=新字符串[]{“toto”,“tata”};
for(int i=0;i

您应该检查其工作原理。

请删除所有内容并使用适当的LINQ。C#不是java