I've been looking for a way to check a string for elements of an array and if it contains one of those elements to return the indexOf it but i'm having trouble finding a way to do this. Most of my searches end up showing me way to find the indexOf an element in an array or something similar.
As a bit of background I'm trying to create a program that takes a string from user input, splits the words of the paragraph into an array, performs certain checks on them and changes them accordingly.
For instance if the current word starts with a consonant it finds the first vowel and moves all the letters in front of it to the end of the word. This is what I tried but it prints an index of 14 so clearly something is wrong:
char[] vowelsList = new char[] { 'A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u' };
foreach (char vowel in vowelsList)
{
if (currentWord.Contains(vowel))
{
int index = currentWord.IndexOf(vowel);
System.Diagnostics.Debug.Write(index);
}
}
currentWord is the word from the string from the user input that is currently being checked.
Any suggestion on different methods or keywords to try is appreciated.
EDIT
I apologise the code is actually fine, it was returning 1 and 4 because it was always receiving the input Hello and i was misinterpreting what was going on, I'm a bit of an idiot sometimes. I guess then my question would be how to get this code to only find the index of the first vowel but a poster has already stated how to do that, thank you all for the help and suggestions, most of which I have implemented.
vowelsList) in a input string? Or each first index of every string in array?currentWordin this example?currentWordin that case, and for whichvowelit prints 14? I don't see anything wrong with this code.