Skip to content

Instantly share code, notes, and snippets.

@Danielkaas94
Last active January 29, 2018 18:22
Show Gist options
  • Save Danielkaas94/6dccc24ad9ae7eefa64459395fcedae7 to your computer and use it in GitHub Desktop.
Save Danielkaas94/6dccc24ad9ae7eefa64459395fcedae7 to your computer and use it in GitHub Desktop.
VowelIndices in my way and as lambda/RegularExpression
private static int[] VowelIndices(string word)
{
List<int> myVowelList = new List<int>();
for (int i = 0; i < word.Length; i++)
{
switch (word.ToLower()[i])
{
case 'a':
myVowelList.Add(i + 1);
break;
case 'e':
myVowelList.Add(i + 1);
break;
case 'i':
myVowelList.Add(i + 1);
break;
case 'o':
myVowelList.Add(i + 1);
break;
case 'u':
myVowelList.Add(i + 1);
break;
case 'y':
myVowelList.Add(i + 1);
break;
default:
break;
}
}
int[] myVowelArray = myVowelList.ToArray();
return myVowelArray;
}
public static int[] VowelIndices2(string word) =>
new Regex("[aeiouy]", RegexOptions.IgnoreCase).Matches(word).Cast<Match>().Select(m => m.Index + 1).ToArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment