How can i check every alphabet inside one string variable? I am trying to make a program that can translate sentences into ones and zeros. look at the code below, that is how much i have done right now. i can read values from a text file and write out the values for only one letter. i want to know how i can write my code to be able to check every letter in a sentence.![enter image description here][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();
If you want iterate over chars in your sentence variable you can use foreach:
foreach (var item in sentence)
{
....
}
In this example item is variable of char type. You can call ToString() method to convert it to string.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다