【问题标题】:How to remove word if appears more than once如果出现不止一次,如何删除单词
【发布时间】:2022-06-21 15:39:04
【问题描述】:

我有一些从服务器获取的字符串,有时它可能会得到带有重复单词的字符串,例如:

"this is example of is example string"

但有时我只得到:

"这是字符串的例子"

我知道只有 "is example" 可以重复,那么,是否有任何快捷方式我不需要查找该字符串的索引并且如果有多个字符串而不需要计数?

【问题讨论】:

    标签: c#


    【解决方案1】:

    你可以使用 Linq

    string nonRepeated = string.Join("my string string".Split(' ').Distinct())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-04
      • 2022-12-18
      相关资源
      最近更新 更多