C # How to get the word that follows a specific word? [closed]

-2

I would like to know how to get the word that follows a specific word in a string, (without knowing what it is or how many words the string has) .Ej:

string: "Eagles fly and dolphins swim", I want to get the word immediately after "the ones", in this case "dolphins" .Thanks

    
asked by Eugenio Monmany 18.03.2018 в 23:39
source

1 answer

0

first you must separate them with a split (''), then go through the array until you find the specific word, you make a next.

string palabras = "Las aguilas vuelan y los delfines nadan";
var arr = palabras.split(' ');
bool encontrada = false;
foreach(var palabra in arr){
     if (encontrada)
       {
           return palabra;
       } 
      if (palabra = "los") encontrada = true;
}
    
answered by 18.03.2018 / 23:47
source