How can i check every alphabet inside one string variable?

SaadRH

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();
user1429899

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can i add a string to the beginning of every line in a file with sed?

분류에서Dev

How can I change the string object inside a string object?

분류에서Dev

How to I check whether a given variable value is of type string

분류에서Dev

How can I check whether a string of words exists in php

분류에서Dev

Can I put a conditional check on a string to see if it ends in "00" inside a LINQ expression?

분류에서Dev

How to find highest alphabet in a String?

분류에서Dev

How do I pass a user input variable inside subprocess_check_output?

분류에서Dev

How can I hide a check box inside my web grid with an if function?

분류에서Dev

How to check if a variable starts with a specific string?

분류에서Dev

How can I check through command-line the computer form(Desktop, notebook or All-in-one)?

분류에서Dev

How do I check if a variable exists in an 'if' statement?

분류에서Dev

How can I check if a string contains only a particular set of special characters in Javascript?

분류에서Dev

How can I check if a line contains specific string from a list of strings?

분류에서Dev

How to reset id's every time I delete one element?

분류에서Dev

How to replace one alphabet by same alphabet and new line character in Java regex

분류에서Dev

How can I check for an @ in a regular expression?

분류에서Dev

How can I check if a gzipped file is empty?

분류에서Dev

How can I check in Apex if a batch is scheduled?

분류에서Dev

How i can check internet connection? android

분류에서Dev

How can I realize that android send one string to a php page and obtain a JSON array?

분류에서Dev

How Can I Test Whether a Variable Contains an Element Value or a String / Number Value? (XSL 1.0)

분류에서Dev

How can I pass HTML code stored in a string variable to a view in MVC 5?

분류에서Dev

selection of at least one check box is must in angular js? I did not get the perfect answer of this how we can do this?

분류에서Dev

How can I detect when an NSTimer changes every minute?

분류에서Dev

How can I generate a random number every 24 hours in JavaScript?

분류에서Dev

How can I run a SQL query iteratively for every row in a table?

분류에서Dev

How can I make a integer for every name in a txt file?

분류에서Dev

How can I make a Python function examine every element of a list?

분류에서Dev

How can I add a text view for every item in my list?

Related 관련 기사

  1. 1

    How can i add a string to the beginning of every line in a file with sed?

  2. 2

    How can I change the string object inside a string object?

  3. 3

    How to I check whether a given variable value is of type string

  4. 4

    How can I check whether a string of words exists in php

  5. 5

    Can I put a conditional check on a string to see if it ends in "00" inside a LINQ expression?

  6. 6

    How to find highest alphabet in a String?

  7. 7

    How do I pass a user input variable inside subprocess_check_output?

  8. 8

    How can I hide a check box inside my web grid with an if function?

  9. 9

    How to check if a variable starts with a specific string?

  10. 10

    How can I check through command-line the computer form(Desktop, notebook or All-in-one)?

  11. 11

    How do I check if a variable exists in an 'if' statement?

  12. 12

    How can I check if a string contains only a particular set of special characters in Javascript?

  13. 13

    How can I check if a line contains specific string from a list of strings?

  14. 14

    How to reset id's every time I delete one element?

  15. 15

    How to replace one alphabet by same alphabet and new line character in Java regex

  16. 16

    How can I check for an @ in a regular expression?

  17. 17

    How can I check if a gzipped file is empty?

  18. 18

    How can I check in Apex if a batch is scheduled?

  19. 19

    How i can check internet connection? android

  20. 20

    How can I realize that android send one string to a php page and obtain a JSON array?

  21. 21

    How Can I Test Whether a Variable Contains an Element Value or a String / Number Value? (XSL 1.0)

  22. 22

    How can I pass HTML code stored in a string variable to a view in MVC 5?

  23. 23

    selection of at least one check box is must in angular js? I did not get the perfect answer of this how we can do this?

  24. 24

    How can I detect when an NSTimer changes every minute?

  25. 25

    How can I generate a random number every 24 hours in JavaScript?

  26. 26

    How can I run a SQL query iteratively for every row in a table?

  27. 27

    How can I make a integer for every name in a txt file?

  28. 28

    How can I make a Python function examine every element of a list?

  29. 29

    How can I add a text view for every item in my list?

뜨겁다태그

보관