using System;
using System.Linq;
class Program
{
static int countOccurences(string text, string searchTerm) {
char[] separators = {'.', '?', '!', ' ', ';', ':', ',', '-'};
string[] arr = text.Split(' ');
var queryResult = from word in arr
where word.Equals(searchTerm, StringComparison.InvariantCultureIgnoreCase)
select word;
return queryResult.Count();
}
static void Main() {
string text = @"
The C# programming language was designed by Anders Hejlsberg from Microsoft in 2000 and was later
approved as an international standard by Ecma (ECMA-334) in 2002 and ISO/IEC (ISO/IEC 23270
and 20619[c]) in 2003. Microsoft introduced C# along with .NET Framework and Visual Studio,
both of which were closed-source. At the time, Microsoft had no open-source products.
Four years later, in 2004, a free and open-source project called Mono began, providing
a cross-platform compiler and runtime environment for the C# programming language.
A decade later, Microsoft released Visual Studio Code (code editor), Roslyn (compiler),
and the unified .NET platform (software framework), all of which support C# and are free,
open-source, and cross-platform. Mono also joined Microsoft but was not merged into .NET.
";
char[] sentenceSeparators = {'.', '?', '!'};
string[] sentences = text.Split(sentenceSeparators, StringSplitOptions.RemoveEmptyEntries);
string[] wordsToMatchInSentences = {"programming", "language"};
char[] separators = {'.', '?', '!', ' ', ';', ':', ','};
var queryResult = from sentence in sentences
let w = sentence.Split(separators,StringSplitOptions.RemoveEmptyEntries)
where w.Distinct().Intersect(wordsToMatchInSentences).Count() == wordsToMatchInSentences.Count()
select sentence;
foreach (string str in queryResult) {
Console.WriteLine(str);
}
}
}
/*
run:
The C# programming language was designed by Anders Hejlsberg from Microsoft in 2000 and was later
approved as an international standard by Ecma (ECMA-334) in 2002 and ISO/IEC (ISO/IEC 23270
and 20619[c]) in 2003
Four years later, in 2004, a free and open-source project called Mono began, providing
a cross-platform compiler and runtime environment for the C# programming language
*/