【问题标题】:How to delete string [] arrays from another string?如何从另一个字符串中删除字符串 [] 数组?
【发布时间】:2022-11-12 19:43:00
【问题描述】:

首先,我定义了我的字符串数组和一个要从中删除单词的字符串:

string[] excludeWords = {"word1","word2","word3","word4","word5"}
   
    string sentence = "word1 word2 word5";

    TextBox1.Text = sentence;

我想从句子中删除 excludeWords 所以我想在我的文本框中输出这个:

word3 word4

我尝试了 except 方法,但没有删除单词:

string filteredText = sentence.Except(excludeWords);

TextBox1.Text = filteredText

我应该使用什么方法?

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-mvc-3


    【解决方案1】:
    var result = excludeWords.Except(sentence.Split(" ")).ToArray();
    

    【讨论】:

      猜你喜欢
      • 2013-03-02
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 1970-01-01
      • 2020-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多