很显然,我对此很陌生,因此也是该项目的内容。我写了一些代码将英语翻译成Pig Latin。很简单。问题是我想找到一种方法来将猪拉丁文翻译成英文使用逻辑块。克隆字符串似乎是一种便宜的方法。有什么建议么?这是我的代码:从拉丁文翻译成英文的C#翻译器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FunctionTest
{
public class PigLatinClass
{
public static void pigTalk(string sentence)
{
try
{
while (sentence != "exit")
{
string firstLetter;
string afterFirst;
string pigLatinOut = "";
int x;
string vowel = "AEIOUaeiou";
Console.WriteLine("Enter a sentence to convert into PigLatin");
sentence = Console.ReadLine();
string[] pieces = sentence.Split();
foreach (string piece in pieces)
{
afterFirst = piece.Substring(1);
firstLetter = piece.Substring(0, 1);
x = vowel.IndexOf(firstLetter);
if (x == -1)
{
pigLatinOut = (afterFirst + firstLetter + "ay ");
}
else
{
pigLatinOut = (firstLetter + afterFirst + "way ");
}
Console.Write(pigLatinOut);
}
Console.WriteLine("Press Enter to flip the sentence back.");
Console.ReadKey(true);
string clonedString = null;
clonedString = (String)sentence.Clone();
Console.WriteLine(clonedString);
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
问题是没有真正的规则可行。例如:如果上一个第三个字母 是“w”,那么您可能想要说这是一个元音字,但是,以“w”开头的辅音字也可以符合此规则。如果第一个字母再次是元音字母,你可能会想说这是一个元音字,但是,从第一个字母移到后面(pat = atpay),辅音字也可以适合这个规则。我认为这是可能的唯一方法是有一个if语句来检查w是否在第三个位置,并且该单词以元音开头,该元音将要求运算符,如果您将它与字符串一起使用,则Visual Studio会对您大喊。
究竟是什么即时通讯思维。所以,在这种特殊情况下,我不是真的错过了一些东西我遇到了不可能的事情? – 2010-11-04 15:44:56
是的,我认为有一个独特的翻译(大部分时间)是不可能的。但是,如果存在多种可能性,也许你可以提供不同的翻译... – digEmAll 2010-11-04 15:56:50
哇,需要大量头脑风暴才能找到所有多个案例......或者我可以创建一个函数来处理这个问题。好。我想我现在走在正确的道路上。感谢digEmAll和所有帮助我的人! – 2010-11-04 16:03:42