Pig Latin Translator吐出多条线? C#

时间:2015-12-20 02:17:20

标签: c# winforms translators

所以我有一个支持多个单词的Pig Latin Translator。但每当我输入一些单词时(为此我们只使用"香蕉苹果剪切巧克力西奥多火车"例如。)它会正确地吐出翻译的单词,但它会重复!这是我的代码:

namespace Pig_Latin_Translator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    List<string> vowels = new List<string>();
    List<string> specials = new List<string>();

    private void TranslateButton_Click(object sender, EventArgs e)
    {
        String[] parts = TranslateBox.Text.Split();
        foreach (string s in specials)
        {
            if (TranslateBox.Text.Contains(s) || TranslateBox.Text == "\"")
            {
                TranslateOutput.Text = "";
                MessageBox.Show("No Special Characters!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                break;
            }
            else
            {
                 foreach (String part in parts)
                {
                    foreach (String v in vowels)
                    {
                        if (part.Substring(0, 1) == v)
                        {
                            TranslateOutput.Text = TranslateOutput.Text + " " + part + "ay";
                            break;
                        }
                        else
                        {
                            if (part.Substring(0, 2) == "sh" || part.Substring(0, 2) == "ch" || part.Substring(0, 2) == "th" || part.Substring(0, 2) == "tr")
                            {
                                string SwitchP = part.Substring(2) + part.Substring(0, 2);
                                TranslateOutput.Text = TranslateOutput.Text + " " + SwitchP + "ay";
                                break;
                            }
                            else
                            {
                                string Switch = part.Substring(1) + part.Substring(0, 1);
                                TranslateOutput.Text = TranslateOutput.Text + " " + Switch + "ay";
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    private void Form1_Load(object sender, EventArgs e)
    {
        vowels.Add("a");
        vowels.Add("e");
        vowels.Add("i");
        vowels.Add("o");
        vowels.Add("u");

        specials.Add("`");
        specials.Add("1");
        specials.Add("2");
        specials.Add("3");
        specials.Add("4");
        specials.Add("5");
        specials.Add("6");
        specials.Add("7");
        specials.Add("8");
        specials.Add("9");
        specials.Add("0");
        specials.Add("-");
        specials.Add("=");
        specials.Add("[");
        specials.Add("]");
        specials.Add(@"\");
        specials.Add(";");
        specials.Add("'");
        specials.Add(",");
        specials.Add(".");
        specials.Add("/");

        specials.Add("~");
        specials.Add("!");
        specials.Add("@");
        specials.Add("#");
        specials.Add("$");
        specials.Add("%");
        specials.Add("^");
        specials.Add("&");
        specials.Add("*");
        specials.Add("(");
        specials.Add(")");
        specials.Add("_");
        specials.Add("+");
        specials.Add("{");
        specials.Add("}");
        specials.Add("|");
        specials.Add(":");
        specials.Add("\"");
        specials.Add("<");
        specials.Add(">");
        specials.Add("?");
    }

    private void AboutButton_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Pig Latin is a fake language. It works by taking the first letter (Or two if it's a pair like 'th' or 'ch') and bringing it to the end, unless the first letter is a vowel. Then add 'ay' to the end. So 'bus' becomes 'usbay', 'thank' becomes 'ankthay' and 'apple' becomes 'appleay'.", "About:", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
}

}

如果您输入&#34;香蕉苹果剪切巧克力西奥多火车&#34;:

&#34; ananabay appleay earshay ocolatechay heodoreTay aintray&#34;重复10次以上。

顺便说一句:对不起,如果你不能回答,因为我知道有很多代码。但这并不重要,因为事情仍然有用。只是它不应该发生并让我紧张。而且我知道还有很多故障,还有很多事要做,但我想先解决这个问题。

0 个答案:

没有答案