Use this to scan each CHARACTER of the STRING.
You can add SWITCH STATEMENT after 1 IF STATEMENT if you want to include "many" characters aside from 'SPACE'.
string myInput = string.Empty;
bool check = false;
// Loops the input module
while (check is false)
{
Console.WriteLine("Enter Letters Only");
myInput = Console.ReadLine();
// Loops the SCANNING PROCCESS of each character of the string
for (int i = 0; i < myInput.Length; i++)
{
// Prints current scanning proccess 1 by 1(character by character) inside the string
Console.WriteLine("Checking Character \"{0}\" ",myInput[i]);
// Letters only
if (Char.IsLetter(myInput[i]))
{
check = true;
}
// Includes "SPACE" character
else if (myInput[i] == ' ')
{
check = true;
}
else
{
check = false;
Console.WriteLine("wrong input. \"{0}\" is not a string", myInput[e]);
Console.WriteLine("pls try again");
// Exits from loop of scanning proccess due to unwanted input
break;
}
}
// Ends SCANNING of 1 CHARACTER inside the string
}
Console.WriteLine("Input Approved: \"{0}\"", myInput);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
OUTPUT: With FALSE Input
Enter Letters Only
Agent 47
Checking Character "A"
Checking Character "g"
Checking Character "e"
Checking Character "n"
Checking Character "t"
Checking Character " "
Checking Character "4"
Oops. "4" is not a Valid Input
pls try again
Enter Letters Only
OUTPUT: Without FALSE Input
Enter Letters Only
Agent Forty Seven
Checking Character "A"
Checking Character "g"
Checking Character "e"
Checking Character "n"
Checking Character "t"
Checking Character " "
Checking Character "F"
Checking Character "o"
Checking Character "r"
Checking Character "t"
Checking Character "y"
Checking Character " "
Checking Character "S"
Checking Character "e"
Checking Character "v"
Checking Character "e"
Checking Character "n"
Input Approved: "Agent Forty Seven"
Press any key to exit
Or SWITCH STATEMENT only, if you only want to include "some" CHARACTERS from LETTER category & "some" CHARATERS from DIGIT category.
switch (myInput[e])
{
case 'a':
case 'b':
case 'c':
case 'd':
case '1':
case '2':
case '3':
case '!':
case '@':
case '#':
check = true;
break;
default:
check = false;
Console.WriteLine("Oops, \"{0}\" is not a string", myInput[i]);
Console.WriteLine("pls try again\n");
break;
}
if (check == false) break ;