Subscribe to danzar's Blog        RSS Feed
-----

Mega Project ideal list. - "Text" section / Pig Latin

Icon Leave Comment
This takes an input string from a text box. Then it first tests for a compound word. It gets the value for the compound word and then tests the results for first letter to vowel then returns the results of that event to the output label.
If its not a compound word then it test for vowel and returns the results and passes it to the output label.

(I am not going to post the whole compound word dictionary I made. Its long and that's after I cut it in half. It is in the source file attached to the blog.)


       private void piglatinConvert_bt_Click(object sender, RoutedEventArgs e)
        {
            string inputstring = piglatinInput_tb.Text;

            if (isCompoundword(inputstring))
            {
                char[] delimiter = new char[] { ' ' };
                string[] array = compoundword(inputstring).Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
                piglatinOutput_lb.Content = makePigLatin(array[0]) + " " + makePigLatin(array[1]);
            }
            else
            {
               piglatinOutput_lb.Content = makePigLatin(inputstring);
            }
            
            

        }
        private static string makePigLatin(string inputstring)
        {
            if (isfirstletterVowel(inputstring))
            { return firstletter_vowel(inputstring); }
            return firstletter_constant(inputstring);

        }
        private static string firstletter_constant(string inputstring)
        {
            string firstletter = inputstring.Substring(0, 1);
            string lastpart = inputstring.Substring(1, inputstring.Length -1);
            return lastpart + "-" + firstletter + "ay";
        }
        private static string firstletter_vowel(string inputstring)
        {
            return inputstring + "-way";
        }
        private static bool isfirstletterVowel(string inputstring)
        {
            string firstletter = inputstring.Substring(0, 1).ToLower();
            if (firstletter == "a" || firstletter == "e" ||
                firstletter == "i" || firstletter == "o" ||
                firstletter == "u" || firstletter == "y")
            { return true; }
            return false;

        }
        private static string compoundword(string inputstring)
        {
            foreach (var item in compoundwords())
            {
                if (item.Key == inputstring)
                { return item.Value; }
            }
            return string.Empty;
        }
        private static bool isCompoundword(string inputstring)
        {
            foreach (var item in compoundwords())
            {
                if (item.Key == inputstring)
                { return true; }
            }
            return false;
        }

Attached File(s)

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

September 2014

S M T W T F S
 123456
78910111213
14 151617181920
21222324252627
282930    

Tags

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)