Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find every options of specific word in text

I am beginner and I am trying to every word, which contains "srv" word in text.
Here is example

Hello, this is test TEST-SRVCole

and I want print TEST-SRVCole

How to do it the most effective way?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is what I have:

 var test = text.Where(x => x.ToString().ToLower().Contains("srv")).ToArray();
            foreach (var item in test)
            {
                Console.WriteLine(item);
            }

But it does not nothing.

>Solution :

This:

var test = text.Where(x => x.ToString().ToLower().Contains("srv")).ToArray();

does nothing, because you literally iterate over characters.

A simple starting point is (a) splitting the string to words, (b) analyzing each of them. Let’s assume a word boundary is just a space:

var parts = text.Split(' ');
foreach (var item in parts.Where(part => part.ToLowerInvariant().Contains("srv")))
{
    Console.WriteLine(item);
}

In reality, the texts you will be processing will, most likely, have other characters as word boundaries, such as punctuation.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading