c# - Is there a function to compare a string to a larger string? -


this question has answer here:

a better way explain question

list names of names contain given string. example, if given string "john,", system display names of every person name contains "john", such "john smith", "elton johns", , "johnny h".

i couldn't explain in question , trying find i'm looking on google when can't phrase right difficult

if search case-sensitive, can use contains:

var name = "john smith"; if(name.contains("john")) {    // name contains john } 

or, all names contain john:

var names = new string[] {"john smith", "bob smith", "frank"}; var results = names.where(n => n.contains("john")); 

if want ignore case, can convert both strings lowercase:

var results = names.where(n => n.tolower().contains("john")); 

you implement own case-insensitive contains function extention method:

public static bool contains(this string value, string substr, stringcomparison c) {   return value.indexof(substr, c) >= 0; } 

then use:

var results = names.where(n => n.contains("john", stringcomparison.ordinalignorecase)); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -