Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Message_Decoder/Program.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
27 lines (26 sloc)
1.09 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string[] lines = File.ReadAllLines("test_words.txt"); // This reads the input coded message from test words | |
string decodedMessage = ""; | |
foreach (string word in lines) // Loops throught the test words file | |
{ | |
if (word == "SPACE") | |
{ | |
decodedMessage += ' '; // Puts a space in the proper position in output | |
} | |
else if (word == "COMMA") | |
{ | |
decodedMessage += ','; // Puts a comma in the proper position in output | |
} | |
else | |
{ | |
if (word.Length > 0) // This is to make sure the word isnt empty | |
{ | |
decodedMessage += word[0]; | |
} | |
else | |
{ | |
decodedMessage += ""; // Replace '\0' with an empty string | |
} | |
} | |
} | |
Console.WriteLine(decodedMessage); // Prints out the output in the terminal | |
File.WriteAllText("decoded.txt", decodedMessage); // Writes the decoded message output to the decoded file |