How to select tokens from a string using LINQ?

I want to select a token from a string, if it exists in a string, I have the following: I'm not sure why it does not compile:

IList<string> tokens = _animals.Split(';');

Func<string, bool> f1 = str => str.Contains("Dog");
Func<string, Func<string, bool>, string> f2 = str => Equals(f1, true);

var selected = tokens.Select(f2);

Greetings

Ollie

+3
source share
4 answers

Or words

var selected = from token in tokens where token.Contains("Dog") select token;
0
source

I think you just need this.

var selected = tokens.Where(str => str.Contains("Dog"));
+5
source

Do you really need LINQ for this? Why can you do something like this:

_animals.Contains("Dog")
+4
source

try it

    var result = (from p in tokens where p.Contains("Dog") select p);
0
source

Source: https://habr.com/ru/post/1708100/


All Articles