Advertisement
Guest User

Reference of how pig latin translator works

a guest
Mar 26th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. private void Form1_Load(object sender, EventArgs e)
  2. {
  3. string ToPigLatin(string sentence)
  4. {
  5.  
  6. const string vowels = "AEIOUaeio";
  7. List<string> pigWords = new List<string>();
  8.  
  9. foreach (string word in sentence.Split(' '))
  10. {
  11. string firstLetter = word.Substring(0, 1);
  12. string restOfWord = word.Substring(1, word.Length - 1);
  13. int currentLetter = vowels.IndexOf(firstLetter);
  14.  
  15. if (currentLetter == -1)
  16. {
  17. pigWords.Add(restOfWord + firstLetter + "ay");
  18. }
  19. else
  20. {
  21. pigWords.Add(word + "way");
  22. }
  23. }
  24. return string.Join(" ", pigWords);
  25. }
  26.  
  27. Console.WriteLine(ToPigLatin("this is a test sentence to see if pig latin actually works and what will become of this"));
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement