Last active
January 29, 2018 18:22
-
-
Save Danielkaas94/6dccc24ad9ae7eefa64459395fcedae7 to your computer and use it in GitHub Desktop.
VowelIndices in my way and as lambda/RegularExpression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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