【发布时间】:2015-01-31 18:56:31
【问题描述】:
如何检查一个字符串变量中的每个字母? 我正在尝试制作一个可以将句子翻译成 1 和 0 的程序。 看看下面的代码,这就是我现在做了多少。我可以从文本文件中读取值并只写出一个字母的值。我想知道如何编写代码以检查句子中的每个字母。![在此处输入图像描述][1]
Dictionary<string, string> dictionary = new Dictionary<string, string>();
string[] lines = File.ReadAllLines("Values.txt");
for (int i = 0; i < 4; i++)
{
string value = lines[i].Substring(4);
string identifier = lines[i].Substring(0, 1);
dictionary.Add(identifier, value);
}
string sentence = Console.ReadLine();
if (sentence == "A")
{
Console.WriteLine(dictionary[sentence]);
}
else if (sentence == "B")
{
Console.WriteLine(dictionary[sentence]);
}
Console.ReadKey();
【问题讨论】:
-
我得到了朋友的帮助。感谢他们在这里提供帮助。