- Course
- Functions C
- Function to check if a text is alphabetical
Function to check if a text is alphabetical
Last updated:
8/23/2020
⁃
Difficulty:
Intermediate
Create a C# program that implements a function called IsAlphabetic that receives a text parameter from the user and check if the text has alphabetic characters from 'a' to 'z' including upper and lower case letters.
Input
Hello
Output
True
Solution
using System;
public class CheckTextAlphabetical
{
public static void Main(string[] args)
{
string text = Console.ReadLine();
Console.WriteLine(IsAlphabetical(text));
}
public static bool IsAlphabetical(string text)
{
text = text.ToUpper();
for (int i = 0; i < text.Length; i++)
{
if (text[i] < 'A' || text[i] > 'Z')
{
return false;
}
}
return true;
}
}