c# - Check Multiple Contains() and store the value dynamically -



c# - Check Multiple Contains() and store the value dynamically -

i have string function in have check multiple characters. code

if(str.contains("r") || str.contains("f") || str.contains("w") ) { string letter= ""; }

my question if string contains r has stored in letter variable, if f contains has stored. how can accomplish not using multiple if conditions??

perhaps want this?

string str = "abcrefg"; var letters = new[] { "r", "f", "w" }; string foundletter = null; foreach (var letter in letters) { if (str.contains(letter)) { foundletter = letter; break; } }

c#

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -