Hi, I am trying to get ahead of my course work for next term and teaching myself c#. I am trying to write a pig latin translator as an exercise from the book I am using but it has no answers. I believe I need to use the split and trim methods and maybe the begins with and ends with methods of the string?
I just dont know how to tie it all together and can't seem to find a working answer online!
Any help would be appreciated:
string english = Convert.ToString(txtEnglish.Text);
string pig = "";
string first;
string last;
string vowels = "AEIOUaeiou";
int consonant;
string[] words = txtEnglish.Text.Split(' ');
foreach (string word in words)
{
try
{
first = word.Substring(0, 1);
last = word.Substring(1, word.Length - 1);
consonant = vowels.IndexOf(first);
if (consonant == -1)
{
pig = last + first + "ay";
}
else
{
pig = word + "way";
}
}
// txtPig.Text = txtPig.ToString();
}
}
}