Hi I'm doing Pig Latin for class, the instructions were first consonant is removed from the front of the word, and put on the back of the word. Then followed by the letters "ay." examples are, book becomes ookbay, and strength becomes engthstray. I'm having trouble because it doesn't do the first consonant.
// button, three, nix, eagle, and troubadour
Console.Write("Enter word you want in Pig Latin: ");
string word1 = Console.ReadLine();
string pig = "";
string vowels = "aeiouAEIOU";
string space = " ";
string extra = ""; //extra letters
int pos = 0; //position
foreach (string word in word1.Split())
{
if (pos != 0)
{
pig = pig + space;
}
else
{
pos = 1;
}
vowels = word.Substring(0,1);
extra = word.Substring(1, word.Length - 1);
pig = pig + extra + vowels + "ay";
}
Console.WriteLine(pig.ToString());
For example if I do strength it will come up as trengthsay and not like the example
vowels
near the top, then overwriting it later. As for your issue, I'd suggest searching for index of the first vowel, then using that as your second arg to the firstsubstring
call (which currently only grabs the first character) - Kreasepos
toword.Length-1
, you can simply writeword.Substring(pos);
- Ian