The problem states "Write a program that accepts a 10-digit telephone number that may contain one or more alphabetic characters. Display the corresponding number using numerals...etc"
ABC:2 through WXYZ:9
This chapter teaches about loops but I found myself really lost at this problem. I completed the code but I think it sucks...
My question: Is there a better way to shorten this code up? And I only figured to use the c# keyword case, is there another way?
EDIT: Arabic as in you could type in 1800WALLTO and it will give you 1800925586
ALSO I am not asking for a code that doesn't work, this does EXACTLY what I want and asked it to do. I am just asking for any advise or input on how to make it better. I really wanted to know a way to do it without switch and case break etc...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x = 0;
char userInput = ' ';
string inputString = "",
outputString = "";
Console.WriteLine("Enter the digits from the phone number");
do
{
userInput = Console.ReadKey(false).KeyChar;
inputString += userInput;
if (Char.IsLetter(userInput))
userInput = userInput.ToString().ToUpper().ToCharArray()[0];
switch (userInput)
{
case '1':
outputString += '1';
x++;
break;
case '2':
case 'A':
case 'B':
case 'C':
outputString += '2';
x++;
break;
case '3':
case 'D':
case 'E':
case 'F':
outputString += '3';
x++;
break;
case '4':
case 'G':
case 'H':
case 'I':
outputString += '4';
x++;
break;
case '5':
case 'J':
case 'K':
case 'L':
outputString += '5';
x++;
break;
case '6':
case 'M':
case 'N':
case 'O':
outputString += '6';
x++;
break;
case '7':
case 'P':
case 'Q':
case 'R':
case 'S':
outputString += '7';
x++;
break;
case '8':
case 'T':
case 'U':
case 'V':
outputString += '8';
x++;
break;
case '9':
case 'W':
case 'X':
case 'Y':
case 'Z':
outputString += '9';
x++;
break;
case '0':
outputString += '0';
x++;
break;
default:
Console.WriteLine("You entered an incorrect value-Try again");
x--;
break;
}
}
while (x < 10);
Console.WriteLine("\nYou entered {0}", inputString);
Console.WriteLine("Your number is {0}", outputString);
}
}
}
Use a System.Collections.Generic.Dictionary where the dictionary keys are the characters A-Z and 0-9 and the values are the corresponding numbers:
var lookup = Dictionary<char, int> {
{'A',2},
{'B',2},
// etc...
{'Z', 9},
{'1':1},
{'2':2}
// etc... include the numerals so you don't have to converts some things to char not the rest...
};
// to lookup a character:
char item = 'A';
int number = lookup['A'];
To decode an phone number just split it into an array of char's and look them up one after the other
List<int> digits = new List<int>();
foreach (char c in inputString)
{
digits.Add(lookup[c]);
}
Im sure somebody will post a 1-liner using LINQ as well, but this is the vanilla version.
Using a string look up would shorten the code:--
String decode "--------------------------------01234567890------2223334445556667778889999---------------------------------"; //256 char string
numout = decode.substring((int) Char.GetNumericValue(userinput),1);
But it would be a lot less efficient than using a "case" statement. Less code does not mean less cpu.
Related
Not a problem as much as a curiosity. I came about this old post yesterday and started playing with it in C#. Heres the original post form 2011(How to change vowels in a string to a symbol?).
I changed some of the code along with a counter to count the total letters in the word. I am stuck on the if statement. I know this program may not have any real world purpose, but I'm trying to learn C# string manipulation.
Console.WriteLine("Enter a word.");
string userWord = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("You wrote {0}", userWord);
Console.WriteLine();
userWord.ToLower();
char[] wordArray = userWord.ToArray();
for (int i = 0; i < wordArray.Length; i++)
{
string theLetter = userWord.Substring(i, 1);
theLetter = theLetter.ToLower();
if (wordArray[i] == 'a' || wordArray[i] == 'e' || wordArray[i] == 'i' || wordArray[i] == 'o' || wordArray[i] == 'u')
{
wordArray[i] = '$';
}
string rebuilt = new string(wordArray);
Console.WriteLine("Your word is now: {0}", rebuilt);
Console.WriteLine("The total number of letters in your word is {0}", userWord.Length);
}
Console.ReadLine();
I just want to change the vowels to $ or any other letter or symbol and count the digits in the word.
The first problem with the C program in the post you linked to is that it only changes the lower-case vowels to '$', not the upper-case ones. The second problem is that strings in C# are immutable, and you already worked around this by changing the word into an array, modifying that, and creating a new string from the modified array.
A method to convert all vowels to '$' might look like this:
public static string VowelsToSymbol(string input)
{
if (string.IsNullOrWhiteSpace(input)) return input;
var work = new char[input.Length];
for (int i = 0; i < work.Length; i++)
{
var c = input[i];
switch (c)
{
case 'A': case 'E': case 'I': case 'O': case 'U':
case 'a': case 'e': case 'i': case 'o': case 'u':
work[i] = '$'; break;
default:
work[i] = c; break;
}
}
return new string(work);
}
Slightly less efficient but much better at showing the intent (what is being done) instead of the mechanics (how is it done):
private static char OneVowelToSymbol(char c)
{
switch (c)
{
case 'A': case 'E': case 'I': case 'O': case 'U':
case 'a': case 'e': case 'i': case 'o': case 'u':
return '$';
default:
return c;
}
}
public static string VowelsToSymbolLinq(string input)
{
return string.IsNullOrWhiteSpace(input) ? input :
new string(input.Select(OneVowelToSymbol).ToArray());
}
If you want to allow for accented characters (or whatever else may count for a vowel in some language other than English), things get ugly quite quickly, and you may be better off using a different method (search the internet for '".NET" isvowel' to find examples).
I'm working a little with switch statements and want to know how to ignore the case sensitivity when it comes to input values.
Here is my code:
using System;
namespace SwitchStatements
{
class MainClass
{
public static void Main(string[] args)
{
Start:
Console.WriteLine("Please Input the Grade");
char grade = Convert.ToChar(Console.ReadLine());
switch (grade)
{
case 'A':
Console.WriteLine("Excellent Work!");
break;
case 'B':
Console.WriteLine("Very Good Effort! Just a couple of Errors =)");
break;
case 'C':
Console.WriteLine("You Passed. Push Yourself Next Time");
break;
case 'D':
Console.WriteLine("Better put in more effort next time. I know you can do better");
break;
default:
Console.WriteLine("Invalid Grade.");
break;
}
Console.ReadKey();
goto Start;
}
}
}
If I put 'a' in instead of 'A' it returns the default response.
Can I use perhaps a .Comparison of some sort? If so where would I put it?
You can use ConsoleKey as condition for switch, the code will be like the following.
var grade =Console.ReadKey().Key;
switch (grade)
{
case ConsoleKey.A:
Console.WriteLine("Excellent Work!");
break;
case ConsoleKey.B:
// Something here
break;
case ConsoleKey.C:
// Something here
break;
case ConsoleKey.D:
// Something here
break;
case ConsoleKey.E:
// Something here
break;
default:
// Something here
break;
}
So that you can avoid converting the input to uppercase/Lower case, and then it goes for another conversion To Char. Simply use ConsoleKey Enumeration inside the switch.
You can use ToUpper(); Like
Convert.ToChar(Console.ReadLine().ToUpper());
and to get saved from the error of getting more charaters with Console.ReadLine() you can use
char grd = Convert.ToChar(Console.ReadKey().KeyChar.ToString().ToUpper());
you can use like following also
char grade = Convert.ToChar(Console.ReadLine().ToUpperInvariant());
https://msdn.microsoft.com/en-us/library/system.string.toupperinvariant.aspx
Convert to uppercase before switch like below,
grade = Char.ToUpper(grade);
Change
char grade = Convert.ToChar(Console.ReadLine());
To
char grade = Convert.ToChar(Console.ReadLine().ToUpper());
https://msdn.microsoft.com/en-us/library/system.string.toupper(v=vs.110).aspx
Write Switch on grade.ToUpper() like this and don't change change it's value, may be you will need it after
char grade = Convert.ToChar(Console.ReadLine());
switch (grade.ToUpper())
{
case 'A':
Console.WriteLine("Excellent Work!");
break;
case 'B':
Console.WriteLine("Very Good Effort! Just a couple of Errors =)");
break;
case 'C':
Console.WriteLine("You Passed. Push Yourself Next Time");
break;
case 'D':
Console.WriteLine("Better put in more effort next time. I know you can do better");
break;
default:
Console.WriteLine("Invalid Grade.");
break;
}
You may fall from one case to another like this
public static void Main(string[] args)
{
Boolean validInputRead = false;
Char grade;
while(!validInputRead)
{
validInputRead = true;
Console.WriteLine("Please Input the Grade");
grade = Convert.ToChar(Console.Read());
switch (grade)
{
case 'A':
case 'a':
Console.WriteLine("Excellent Work!");
break;
case 'B':
case 'b':
Console.WriteLine("Very Good Effort! Just a couple of Errors =)");
break;
case 'C':
case 'c':
Console.WriteLine("You Passed. Push Yourself Next Time");
break;
case 'D':
case 'd':
Console.WriteLine("Better put in more effort next time. I know you can do better");
break;
default:
Console.WriteLine("Invalid Grade.");
validInputRead = false;
break;
}
Console.ReadKey();
}
}
EDIT
Changed from Console.ReadLine() to Console.Read() as suggested
Added while(!validInputRead) as requested
string letterGrade;
int grade = 0;
// This will hold the final letter grade
Console.Write("Input the grade :");
switch (grade)
{
case 1:
// 90-100 is an A
letterGrade = "A";
Console.WriteLine("grade b/n 90-100");
break;
case 2:
// 80-89 is a B
letterGrade = "B";
Console.WriteLine("grade b/n 80-89");
break;
case 3:
// 70-79 is a C
letterGrade = "C";
Console.WriteLine("grade b/n 70-79");
break;
case 4:
// 60-69 is a D
letterGrade = "D";
Console.WriteLine(" grade b/n 60-69 ");
break;
default:
// point whic is less than 59
Console.WriteLine("Invalid grade");
break;
}
I've made a program where I can decrypt some encrypted text, it does this by reading a text file and shifting the text one letter at a time, and it does this 26 times, but I can't get it to save and write the output to a text file, this is my code below, I would appreciate any help if possible, thank you
using System;
using System.IO;
namespace Assignment1
{
class MainClass
{
public static void Main(string[] args)
{
//Writing to the screen
Console.WriteLine("Welcome to the Ceaser Cipher Shift Program");
Console.WriteLine("Would You Like to Decrypt a File (y for yes/n for no)");
string userValue = Console.ReadLine();
//User's value is set to userValue
// if the user types "y", activate the decryption method
if (userValue.ToLower() == "y")
{
decryption();
}
// if the user types in "n", write "Goodbye" and close the program
if (userValue.ToLower() == "n")
{
Console.WriteLine("Goodbye");
Console.ReadLine();
Environment.Exit(0);
//Environment.exit closes the program
}
}
//Decryption method
public static void decryption()
{
//ShiftLine is equal to new char
char[] ShiftLine = new char[0];
//If the shift is smaller or equal to 25, continue to shift one at a time
for (int shift = 1; shift <= 26; shift++)
{
//This reads the encryptefd text file into the program
string textFile = #"C:\Users\Anthony\Desktop\caesarShiftEncoded.txt";
//The string "test" reads all the lines of the textFile
string[] text = File.ReadAllLines(textFile);
foreach (string line in text)
{
//Sets currentLetter to 0
int CurrentLetter = 0;
int[] ShiftNumbers = new int[line.Length];
ShiftLine = new char[line.Length];
foreach (char letter in line)
{
ShiftNumbers[CurrentLetter] = ConvertLetterToNumber(letter);
ShiftNumbers[CurrentLetter] = ShiftCipher(ShiftNumbers[CurrentLetter], shift);
ShiftLine[CurrentLetter] = ConvertNumberToLetter(ShiftNumbers[CurrentLetter]);
CurrentLetter++;
}
Console.WriteLine(string.Join("", ShiftLine));
}
//Console.WriteLine (textFile.Length);
Console.WriteLine("This is Shift No: {0}", shift);
}
Console.WriteLine("Which Shift Would You Like To Write to a Text File: ");
string userNumber = Console.ReadLine();
if (userNumber.ToLower() == "1 =< 26")
{
using (StreamWriter text = new StreamWriter("TextWrittenFile.txt"))
{
foreach (char line in ShiftLine)
{
text.WriteLine(ShiftLine);
File.WriteAllText("C:\Users\Anthony\Desktop\DecryptedText.txt", ShiftLine);
}
}
}
}
public static int ShiftCipher(int Number, int Shift)
{
if (Number == 27)
{
return 27;
}
else if (Number == 28)
{
return 28;
}
else if (Number > Shift)
{
return (Number - Shift);
}
else if (Number <= Shift)
{
return (26 + (Number - Shift));
}
else
{
return 0;
}
}
public static int ConvertLetterToNumber(char Letter)
{
switch (Char.ToLower(Letter))
{
case 'a':
return 1;
case 'b':
return 2;
case 'c':
return 3;
case 'd':
return 4;
case 'e':
return 5;
case 'f':
return 6;
case 'g':
return 7;
case 'h':
return 8;
case 'i':
return 9;
case 'j':
return 10;
case 'k':
return 11;
case 'l':
return 12;
case 'm':
return 13;
case 'n':
return 14;
case 'o':
return 15;
case 'p':
return 16;
case 'q':
return 17;
case 'r':
return 18;
case 's':
return 19;
case 't':
return 20;
case 'u':
return 21;
case 'v':
return 22;
case 'w':
return 23;
case 'x':
return 24;
case 'y':
return 25;
case 'z':
return 26;
case ' ':
return 27;
default:
return 0;
}
}
public static char ConvertNumberToLetter(int Number)
{
switch (Number)
{
case 1:
return 'a';
case 2:
return 'b';
case 3:
return 'c';
case 4:
return 'd';
case 5:
return 'e';
case 6:
return 'f';
case 7:
return 'g';
case 8:
return 'h';
case 9:
return 'i';
case 10:
return 'j';
case 11:
return 'k';
case 12:
return 'l';
case 13:
return 'm';
case 14:
return 'n';
case 15:
return 'o';
case 16:
return 'p';
case 17:
return 'q';
case 18:
return 'r';
case 19:
return 's';
case 20:
return 't';
case 21:
return 'u';
case 22:
return 'v';
case 23:
return 'w';
case 24:
return 'x';
case 25:
return 'y';
case 26:
return 'z';
case 27:
return ' ';
default:
return '0';
}
}
}
}
As your ShiftLine seems to be an array of chars it could be as simple as that:
File.WriteAllText("C:\Users\Anthony\Desktop\DecryptedText.txt", new string(ShiftLine));
(instead of your loop [btw: Your loop overwrites the file on any turn...])
Actually there are a few things you could improve.
If the user shall only be able to press y or n, you could use the Console.ReadKey() method instead of letting the user input a complete line of text. By using the overloaded method and specifying true as argument, you won't even see the pressed key on written into the console window (Console.ReadKey(true)).
So you could exchange the current if statements with switch (Console.ReadKey(true).Key) and build cases like case ConsoleKey.Y:
So the Main method would look something like that:
public static void Main(string[] args)
{
//Writing to the screen
Console.WriteLine("Welcome to the Ceaser Cipher Shift Program");
Console.WriteLine("Would You Like to Decrypt a File (y for yes/n for no)");
switch (Console.ReadKey(true).Key)
{
// if the user types "y", activate the decryption method
case ConsoleKey.Y:
decryption();
break;
// if the user types in "n", write "Goodbye" and close the program
case ConsoleKey.N:
default:
Console.WriteLine("Goodbye");
Environment.Exit(0);
break;
}
}
I guess the next thing you want to do is using Caesar cipher for encrypting/decrypting data.
Therefore you "just" need to shift every character and this can be done much easier than writing switch-case statements like you did. The idea behind this type of encryption is, that you take one character and replace it with another one which is offset characters away. Decrypting goes the other way.
So it would be much easier building one method that has the ability to do exactly that for a specified text.
There are two special cases you need to consider: What happens if the value you are looking at is on the lower boundary and you substract the offset (meaning, the "new" value would be lower than zero). The second one represents the same situation on the upper boundary.
These sitations can be resolved using either if statements or possibly easier by just looking at the rest of the division with the maximum value range. (text[i] + offset) % NumberOfPossibleCharacters should do the trick.
Knowing this you can easily build a method like the following one (where I have assumed, that there is no character with a value greater than 127):
static string Encrypt(string data, int offset)
{
string result = string.Empty;
for (int i = 0; i < data.Length; i++)
{
// Add the offset to the current character and just take the
// rest of the division by 127. Afterwards cast it back to a character
// (because it will be a number due to + and %)
result += (char)((data[i] + offset) % 127);
}
return result;
}
Be advised, that string operations like += will cause the creation of a new string each time so it is not a good example from an (memory)performance point of view. There is the better way of using the StringBuilder class.
I hope this hint's you in a better way of solving your homework ;-)
I am developing a console application, that should listen for digits from a numpad keyboard in both num lock states - on and off. The application is running on Raspberry Pi with Arch Linux and Mono. Since I did not found a way, that is compiling under Mono, to permanently turn numlock on, I am using the following method to convert num pad commands to digits:
private string ReadNumPadSymbol(ConsoleKeyInfo keyInfo)
{
char editedSymbol;
switch (keyInfo.Key)
{
case ConsoleKey.Insert:
editedSymbol = '0';
break;
case ConsoleKey.End:
editedSymbol = '1';
break;
case ConsoleKey.DownArrow:
editedSymbol = '2';
break;
case ConsoleKey.PageDown:
editedSymbol = '3';
break;
case ConsoleKey.LeftArrow:
editedSymbol = '4';
break;
case ConsoleKey.Clear:
editedSymbol = '5';
break;
case ConsoleKey.RightArrow:
editedSymbol = '6';
break;
case ConsoleKey.Home:
editedSymbol = '7';
break;
case ConsoleKey.UpArrow:
editedSymbol = '8';
break;
case ConsoleKey.PageUp:
editedSymbol = '9';
break;
default:
return String.Empty;
}
return editedSymbol.ToString();
}
It works as expected under Windows, but under Linux, the method returns empty string, when the "5" button is pressed. For some reason it does not enters the ConsoleKey.Clear case. Is there a fix for this?
Thanks!
I am working on a homework assignment, beginning C#.
Have to accept input from user:
phone number with numbers or characters
then return only the numeric version of number.
My program takes input and returns value, but does not end when 10 characters have been entered.
You can enter as many characters as you want, then when enter is pressed it only displays first 10.
It also does not test the cases after each character entered. Seems to do at the end.
I would like to have each character tested after input and then once ten characters have been entered
the program display results.
I hope I am giving enough info. I am pretty stressed about this.
It is due tomorrow and I have a few other programs to do yet.
Any help would be greatly appreciated.
My code:
Console.Write("Please enter your phone number: ");
do
{
int temp = Console.Read();
input = Convert.ToChar(temp);
//int tempInput = Convert.ToString(tempInput);
switch (input)
{
case '0':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += input.ToString();
counter--;
break;
// { other cases }
default:
// if input does not match cases then loop returns to
// request new input
Display.Error(input.ToString());
Console.Write(alphaNumericPhoneNumber);
//Display.Continue();
//Console.Clear();
input = ' ';
break;
}
}
while (numericPhoneNumber.Length < 0);
return numericPhoneNumber;
}
The documentation for the Console.Read() method explains the described behavior.
The Read method blocks its return while you type input characters; it terminates when you press the Enter key. [...] Subsequent calls to the Read method retrieve your input one character at a time.
If you want to process the characters as they arrive, you may use the KeyAvailableand ReadKey methods as demonstrated in the documentation. The example is available in 5 .NET languages, including C#.
Basically you need to use Console.ReadKey() instead of Console.Read() as the latter expects a \n from an ENTER press to return and the former returns immediately when key is pressed.
class Program
{
static void Main(string[] args)
{
ReadPhone();
Console.ReadLine();
}
private static void ReadPhone()
{
var numericPhoneNumber = string.Empty;
Console.Write("Please enter your phone number: ");
do
{
var keyInfo= Console.ReadKey();
if (char.IsDigit(keyInfo.KeyChar))
{
numericPhoneNumber += keyInfo.KeyChar;
}
else
{
Console.WriteLine();
Console.WriteLine("Please enter numeric numbers only");
}
}
while (numericPhoneNumber.Length <= 10);
Console.WriteLine("Phone Number: {0}", numericPhoneNumber);
}
}
static void Main(string[] args)
{
int i=0;
string str=String.Empty;
Char c;
Console.WriteLine("Enter number:");
while (i < 10)
{
if (char.IsDigit(c = Console.ReadKey().KeyChar))
{
str += c;
i++;
}
}
Console.WriteLine("str: "+str);
}
Thanks to everyone for your help.
I ended up using the readkey to evaluate each character and assign its respective numerical value as per the telephone keypad.
I don't think that I was very clear about it in my original post... little stressed about it at the time... spent to long on this question.
The replies to this post showed some pretty clean code. I hope to get to that level soon.
I will show what I ended up doing, just incase someone in interested.
Thanks again for your help.
class Request
{
public static void GetPhoneNumber(out string UserInput, out string ConvertedString)
{
// create instance of ConsoleKeyInfo
ConsoleKeyInfo cki = new ConsoleKeyInfo();
string alphaNumericPhoneNumber = " ";
string numericPhoneNumber = " ";
char input = ' ';
Console.Write("Please enter your phone number: ");
// perform a do... while loop to read 10 characters of input
do
{
cki = Console.ReadKey();
input = cki.KeyChar;
switch (char.ToUpper(input))
{
case '0':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += input.ToString();
break;
case '1':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += input.ToString();
break;
case 'A':
case 'B':
case 'C':
case '2':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += "2";
break;
case 'D':
case 'E':
case 'F':
case '3':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += "3";
break;
case 'G':
case 'H':
case 'I':
case '4':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += "4";
break;
case 'J':
case 'K':
case 'L':
case '5':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += "5";
break;
case 'M':
case 'N':
case 'O':
case '6':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += "6";
break;
case 'P':
case 'Q':
case 'R':
case 'S':
case '7':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += "7";
break;
case 'T':
case 'U':
case 'V':
case '8':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += "8";
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
case '9':
alphaNumericPhoneNumber += input.ToString();
numericPhoneNumber += "9";
break;
default:
// if input does not match cases then loop returns to
// request new input
Console.Clear();
Display.Error(input.ToString());
// display for user to continue... displays valid numbers so far
Console.Write("Continue with phone number: " + alphaNumericPhoneNumber);
input = ' '; // returns blank character and not added to strings so not counted
break;
}
}
while (numericPhoneNumber.Length < 11); // counts until string has 10 digits
UserInput = alphaNumericPhoneNumber;
ConvertedString = numericPhoneNumber;
}
}
Ok, not so sure about helping you with your homework. I used to sell my assignments to other kids when I was studying, so I guess I can't take the moral high ground here.
Here's a solution, but make sure you do some googling and understand how it works.
// Initialise the result to nothing.
string result = string.Empty;
do
{
// Prompt for input.
Console.WriteLine("Please enter your 10-digit phone number: ");
// Read the response.
string input = Console.ReadLine();
// Replace any characters that are not numbers with the empty string (remove them).
result = System.Text.RegularExpressions.Regex.Replace(input, "[^0-9]", string.Empty);
}
while (result.Length != 10);
// Do something with the result.
Console.WriteLine("You typed: '{0}'.", result);
If you want to read one character at a time (which sounds a bit odd to me), then you could do something like:
// Initialise the result to nothing.
string result = string.Empty;
// Prompt for input.
Console.WriteLine("Please enter your 10-digit phone number: ");
do
{
string input = Console.ReadKey().KeyChar.ToString();
// Replace any characters that are not numbers with the empty string (remove them).
result += Regex.Replace(input, "[^0-9]", string.Empty);
}
while (result.Length != 10);
// Do something with the result.
Console.WriteLine("You typed: '{0}'.", result);