Creating a Pig Latin Program in C#
Do you want to learn how to create a program in C# that will generate pig Latin based on what you type? Well it may be pretty useless but this program does allow you to see some concepts in action. For example, adding concatenated strings to an Array List, splitting a sentence into an array of single words and using the length property of strings in concert with the Substring member of string to create a new word. Of course this program doesn't abide by all the rules in pig latin, but you'll get the point.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace pe7_6
{
class PigLatin
{
static void
{
string[] pLatin;
string phrase;
ArrayList pLatinPhrase = new ArrayList();
int wordLength;
Console.WriteLine("Enter a phrase that you want converted " +
"into pig latin.");
phrase = Console.ReadLine();
pLatin = phrase.Split();
foreach (string pl in pLatin)
{
wordLength = pl.Length;
pLatinPhrase.Add(pl.Substring(1, wordLength - 1) + pl.Substring(0, 1) + "ay");
}
foreach (string p in pLatinPhrase)
Console.Write("{0} ", p);
Console.ReadLine();
}
}
}