Monday, 1 June 2015

Check String contains purticular value from array or text file comma separated string

Hello All,

string text = System.IO.File.ReadAllText(@"Your_File_Path");

Here file contains comma seperated or single value, like abc or abc,def,... etc

String Str = "Your_String_Goes_Here";

Str holds the text in which we want to chech wheather a purticular value exists or not.

var result = text.ToLower().Split(',').Any(sc => Str.ToLower().Contains(sc));

if (result == true)
{
    // Code here
}
else
{
    // Code here
}

That's it, enjoy...

No comments:

Post a comment