![]() |
VOOZH | about |
Given a string, now we all know that the task is to check whether a string contains only alphabets. Now we will be iterating character by character and checking the corresponding ASCII value attached to it. If not found means there is some other character other than "a-z" or "A-Z". If we traverse the whole string and land up on finding all characters in a string within this domain pool then the string is surely only alphabetic.
Examples:
Input: GeeksforGeeks
Output: TrueInput: Geeks4Geeks
Output: FalseInput: null
Output: False
In this article, the characters of the string are checked one by one using their ASCII values.
Algorithm:
- Get the string
- Match the string:
- Check if the string is empty or not. If empty, return false
- Check if the string is null or not. If null, return false.
- If the string is neither empty nor null, then check the string characters one by one for alphabet using ASCII values.
- Return true if matched
Example 1:
true
Complexity Analysis:
Example 2:
Test Case 1: Input: GeeksforGeeks Output: true Test Case 2: Input: Geeks4Geeks Output: false Test Case 3: Input: null Output: false Test Case 4: Input: Output: false
Complexity Analysis:
Related Articles: