【发布时间】:2008-12-07 10:46:55
【问题描述】:
我编写了一个代码来翻译字符串以匹配从数组 0ne 到数组 2 的每个单词,并显示正确的结果。但是如何让编译器把字符串中的数字按原样打印出来,嗯嗯看我写的代码
class Program
{
public static string[] E = { "i", "go", "school", "to", "at" };
public static string[] A = { "Je", "vais", "ecole", "a", "a" };
public static string Translate(string s)
{
string str = "";
Regex Expression = new Regex(@"[a-zA-Z]+");
MatchCollection M = Expression.Matches(s);
foreach (Match x in M)
str = str + " " + TranslateWord(x.ToString());
return str;
}
public static string TranslateWord(string s)
{
for (int i = 0; i < E.Length; i++)
if (s.ToLower() == E[i].ToLower())
return A[i];
return "Undefined";
}
在这里我想输入整个字符串,代码应该用数字翻译它,现在我知道如何做这个词(通过拆分它们并翻译)但是数字呢)
static void Main(string[] args)
{
string str = "I go to school at 8";
Console.WriteLine(Translate(str));
}
如何继续?!
【问题讨论】: