C# 我怎么能忽略14个标点符号

C# 我怎么能忽略14个标点符号,c#,C#,我需要在字符串中找到相同的单词,我使用split方法将其拆分为单词,但我得到了错误,因为berhan与berhan,不同。我将标点符号保留在一系列中如何删除它们如果一个单词X(停止词除外)在文本中出现两次以上,计算机会问“你喜欢X吗?假设停止词存储在以下数组中: string[] stop_words = {″a″, ″after″, ″again, ″all″, ″am″, ″and″, ″any″, ″are″, ″as″, ″at″, ″be″, ″been″, ″before″, ″be

我需要在字符串中找到相同的单词,我使用split方法将其拆分为单词,但我得到了错误,因为
berhan
berhan,
不同。我将标点符号保留在一系列中如何删除它们如果一个单词X(停止词除外)在文本中出现两次以上,计算机会问“你喜欢X吗?假设停止词存储在以下数组中:

string[] stop_words = {″a″, ″after″, ″again, ″all″, ″am″, ″and″, ″any″, ″are″, ″as″, ″at″, ″be″, ″been″, ″before″, ″between″, ″both″, ″but″, ″by″, ″can″, ″could″, ″for″, ″from″, ″had″, ″has″, ″he″, ″her″, ″here″, ″him″, ″in″, ″into″, ”I”, ″is″, ″it″, ″me″, ″my″, ″of″, ″on″, ″our″, ″she″, ″so″, ″such″, ″than″, ″that″, ″the″, ″then″, ″they″, ″this″, ″to″, ″until″, ″we″, ″was″, ″were″, ″with″, ″you″} 
例如输入:

你好,我有一把吉他,我的吉他是蓝色的输出:你喜欢吉他吗

我使用分割法,但“吉他”不等于“吉他”

我建议提取单词而不是分割(当你有多达14个标点符号时,有可能有一个15th一个,比如
-
U+055C
亚美尼亚感叹号);尝试为此使用正则表达式:

  using System.Text.RegularExpressions;

  ...

  string source = @"A lot of words: there're some Russian ones (русские слова).";

  string[] words = Regex
    .Matches(source, @"[\p{L}']+") // word is composed from letters and apostrophes
    .OfType<Match>()
    .Select(match => match.Value)
    .ToArray();

  Console.Write(string.Join(Environment.NewLine, words)); 
如果要查找相同的(重复的)单词,请添加分组(
GroupBy
)以摆脱停止单词筛选(
Where
):


这可能会让您感到惊讶,但多达593(甚至不接近14

欢迎来到Stack Overflow!请编辑您的问题以包含您的代码,并显示您面临的挑战。同时请显示一些示例输入数据(以及预期/实际输出)。如果没有代码,也没有任何东西显示您正在解析的示例字符串,那么很难尝试回答这样的问题。例如输入:你好,我有一把吉他,我的吉他是蓝色的输出:你喜欢吉他吗?我使用分割法,但“吉他”不等于“吉他”“好的,很好-请编辑您的问题-在注释中以未格式化文本的形式阅读代码是相当困难的。另外,很好,您共享了一些输入数据,以及您计划如何使用这些数据。还请分享您编写的代码,以及您遇到的问题。你提到已经分门别类了;这将是非常有帮助的显示。否则,它将显示为“请为我编写代码”(这与主题无关)。您只想从字符串中删除标点符号吗?这可以通过
A
lot
of
words
there're
some
Russian
ones
русские
слова
  HashSet<string> stopWords = 
    new HashSet<string>(StringComparer.CurrentCultureIgnoreCase) {
      "is", "a", //TODO: put stopwords here 
  };

  string[] repeatedWords = Regex
    .Matches(source, @"[\p{L}']+") // word is composed from letters and apostrophes
    .OfType<Match>()
    .Select(match => match.Value)
    .Where(word => !stopWords.Contains(word)) // not a stopword
    .GroupBy(word => word, StringComparer.CurrentCultureIgnoreCase)
    .Where(group => group.Count() > 2) // appeared more than 2 times
    .Select(group => group.Key)
    .ToArray();
  int count = Enumerable
    .Range(0, char.MaxValue)
    .Count(c => char.IsPunctuation((char)c));

  Console.Write(count);