0

I am new in c# and stucked with getting value from arrays. I can check if the string contains any string in array but i have no idea how to get the value of matched string.

In my code i want to get "When is" as a string.

string testwords = "When is your birthday";
string[] myStrings = { "Who is ", "When is ", "What is " };

if(myStrings.Any(testwords.Contains))
3
  • This might also help you out dotnetfiddle.net/UdNrbk Commented Oct 7, 2020 at 0:44
  • "i have no idea how to get the value of matched string" -- to do that, you'd have to know the index of the item that matched. And to do that, you can use the FindIndex() method. See duplicates. Your predicate might be just like you show above, i.e. testwords.Contains. Commented Oct 7, 2020 at 0:45
  • @MichaelRandall you are a hero! This is exactly what i want. Thank you so much! Commented Oct 7, 2020 at 0:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.