Help how to find all the different words in the text, or at least give an idea. Nothing comes to mind

Closed due to the fact that the issue is too common for participants iluxa1810 , Bald , HamSter , Kromster , aleksandr barakin Nov 18 Nov '16 at 15:53 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Help for the regulars here is ru.stackoverflow.com/questions/236947/… - nick_n_a
  • four
    Why regular? string.Split by delimiters and Distinct result. - Vlad
  • @Vlad, which characters are the delimiters? - Qwertiy
  • @nick_n_a, constructions in C # may differ - Grundy
  • @Qwertiy, punctuation, spaces, dashes, brackets. - Vlad

2 answers 2

http://ideone.com/AH5jHw

 using System; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var s = "One thing is not the other one, even if it is one"; var res = Regex.Matches(s, @"\b\w+\b").OfType<Match>().Select(m => m.Value).Distinct(); Console.WriteLine(String.Join(" ", res)); } } 
     using System; using System.Collections.Generic; using System.Linq; namespace First_App { class Program { static void Main(string[] args) { string Text = "Привет, мой друг! Я очень надеюсь, что данный пример тебе помог. ДрУг, Запомни, что 2*2=4, а 3-1=\"2\""; List<string> result = Text.ToLower().Split(new string[] { " ", "/", "*", ".", "=", "!", "-", "\"", "," }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(); } } } 

    1) You need words, so use .ToLower to get away from case dependency.

    2) In the new string [] array, specify delimiters that you do not need.

    • There are many delimiters. In my opinion, \b in regulars is more reliable. - Qwertiy
    • Here I am ready to argue with you. Regularity, which is used as a response below does not take into account the first and last words in the sentence. You can familiarize yourself with the approximate work of this expression under the link Regular expressions of C # - Elies
    • How it will not consider? There is an example on ideone. The first word One is as a result, the last is not, because it occurs earlier. ideone.com/MWzE1C - here, all the words are in place. - Qwertiy
    • The result contains the word "one" because it is encountered in the middle of a sentence. - Elies
    • I gave another link in the comments - there are 3 different words and all 3 got into the result. And in the example in the answer there is One , which was the first and one , which was in the middle - they have a different register. There is no last one , since it repeats the central one. Well, to do case insensitive, you can add .ToLower() either to the original line or to m.Value . - Qwertiy