Check if a string contains only alphabets
Here given code implementation process.
// C Program for
// Check if a string contains only alphabets
#include <stdio.h>
#include <string.h>
void isAllAlphabets(char *text)
{
int n = strlen(text);
if (n == 0)
{
// Empty String
return;
}
printf("\n Given text : %s ", text);
int i = 0;
while (i < n)
{
if (text[i] >= 'a' && text[i] <= 'z' ||
(text[i] >= 'A' && text[i] <= 'Z'))
{
// When alphabets occurs
i++;
}
else
{
printf("\n No ");
return;
}
}
// When all alphabets character
printf("\n Yes ");
}
int main(int argc, char
const *argv[])
{
// Test
isAllAlphabets("xyzklsadfl");
isAllAlphabets("code2Solve");
isAllAlphabets("sdxfsd-cf");
isAllAlphabets("kalkicode");
isAllAlphabets("FiveDiv");
return 0;
}
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
// Java program for
// Check if a string contains only alphabets
public class Alphabets
{
public void isAllAlphabets(String text)
{
int n = text.length();
if (n == 0)
{
// Empty String
return;
}
System.out.print("\n Given text : " + text);
int i = 0;
while (i < n)
{
if (text.charAt(i) >= 'a' && text.charAt(i) <= 'z' ||
(text.charAt(i) >= 'A' && text.charAt(i) <= 'Z'))
{
// When alphabets occurs
i++;
}
else
{
System.out.print("\n No ");
return;
}
}
// When all alphabets character
System.out.print("\n Yes ");
}
public static void main(String[] args)
{
Alphabets task = new Alphabets();
// Test
task.isAllAlphabets("xyzklsadfl");
task.isAllAlphabets("code2Solve");
task.isAllAlphabets("sdxfsd-cf");
task.isAllAlphabets("kalkicode");
task.isAllAlphabets("FiveDiv");
}
}
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
// Include header file
#include <iostream>
#include <string>
using namespace std;
// C++ program for
// Check if a string contains only alphabets
class Alphabets
{
public: void isAllAlphabets(string text)
{
int n = text.length();
if (n == 0)
{
// Empty String
return;
}
cout << "\n Given text : " << text;
int i = 0;
while (i < n)
{
if (text[i] >= 'a' && text[i] <= 'z' ||
(text[i] >= 'A' && text[i] <= 'Z'))
{
// When alphabets occurs
i++;
}
else
{
cout << "\n No ";
return;
}
}
// When all alphabets character
cout << "\n Yes ";
}
};
int main()
{
Alphabets *task = new Alphabets();
// Test
task->isAllAlphabets("xyzklsadfl");
task->isAllAlphabets("code2Solve");
task->isAllAlphabets("sdxfsd-cf");
task->isAllAlphabets("kalkicode");
task->isAllAlphabets("FiveDiv");
return 0;
}
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
package main
import "fmt"
// Go program for
// Check if a string contains only alphabets
type Alphabets struct {}
func getAlphabets() * Alphabets {
var me *Alphabets = &Alphabets {}
return me
}
func(this Alphabets) isAllAlphabets(text string) {
var n int = len(text)
if n == 0 {
// Empty String
return
}
fmt.Print("\n Given text : ", text)
var i int = 0
for (i < n) {
if text[i] >= 'a' && text[i] <= 'z' ||
(text[i] >= 'A' && text[i] <= 'Z') {
// When alphabets occurs
i++
} else {
fmt.Print("\n No ")
return
}
}
// When all alphabets character
fmt.Print("\n Yes ")
}
func main() {
var task * Alphabets = getAlphabets()
// Test
task.isAllAlphabets("xyzklsadfl")
task.isAllAlphabets("code2Solve")
task.isAllAlphabets("sdxfsd-cf")
task.isAllAlphabets("kalkicode")
task.isAllAlphabets("FiveDiv")
}
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
// Include namespace system
using System;
// Csharp program for
// Check if a string contains only alphabets
public class Alphabets
{
public void isAllAlphabets(String text)
{
int n = text.Length;
if (n == 0)
{
// Empty String
return;
}
Console.Write("\n Given text : " + text);
int i = 0;
while (i < n)
{
if (text[i] >= 'a' && text[i] <= 'z' ||
(text[i] >= 'A' && text[i] <= 'Z'))
{
// When alphabets occurs
i++;
}
else
{
Console.Write("\n No ");
return;
}
}
// When all alphabets character
Console.Write("\n Yes ");
}
public static void Main(String[] args)
{
Alphabets task = new Alphabets();
// Test
task.isAllAlphabets("xyzklsadfl");
task.isAllAlphabets("code2Solve");
task.isAllAlphabets("sdxfsd-cf");
task.isAllAlphabets("kalkicode");
task.isAllAlphabets("FiveDiv");
}
}
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
<?php
// Php program for
// Check if a string contains only alphabets
class Alphabets
{
public function isAllAlphabets($text)
{
$n = strlen($text);
if ($n == 0)
{
// Empty String
return;
}
echo("\n Given text : ".$text);
$i = 0;
while ($i < $n)
{
if ($text[$i] >= 'a' && $text[$i] <= 'z' ||
($text[$i] >= 'A' && $text[$i] <= 'Z'))
{
// When alphabets occurs
$i++;
}
else
{
echo("\n No ");
return;
}
}
// When all alphabets character
echo("\n Yes ");
}
}
function main()
{
$task = new Alphabets();
// Test
$task->isAllAlphabets("xyzklsadfl");
$task->isAllAlphabets("code2Solve");
$task->isAllAlphabets("sdxfsd-cf");
$task->isAllAlphabets("kalkicode");
$task->isAllAlphabets("FiveDiv");
}
main();
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
// Node JS program for
// Check if a string contains only alphabets
class Alphabets
{
isAllAlphabets(text)
{
var n = text.length;
if (n == 0)
{
// Empty String
return;
}
process.stdout.write("\n Given text : " + text);
var i = 0;
while (i < n)
{
if (text.charAt(i) >= 'a' && text.charAt(i) <= 'z' ||
(text.charAt(i) >= 'A' && text.charAt(i) <= 'Z'))
{
// When alphabets occurs
i++;
}
else
{
process.stdout.write("\n No ");
return;
}
}
// When all alphabets character
process.stdout.write("\n Yes ");
}
}
function main()
{
var task = new Alphabets();
// Test
task.isAllAlphabets("xyzklsadfl");
task.isAllAlphabets("code2Solve");
task.isAllAlphabets("sdxfsd-cf");
task.isAllAlphabets("kalkicode");
task.isAllAlphabets("FiveDiv");
}
main();
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
# Python 3 program for
# Check if a string contains only alphabets
class Alphabets :
def isAllAlphabets(self, text) :
n = len(text)
if (n == 0) :
# Empty String
return
print("\n Given text : ", text, end = "")
i = 0
while (i < n) :
if (text[i] >= 'a'
and text[i] <= 'z'
or(text[i] >= 'A'
and text[i] <= 'Z')) :
# When alphabets occurs
i += 1
else :
print("\n No ", end = "")
return
# When all alphabets character
print("\n Yes ", end = "")
def main() :
task = Alphabets()
# Test
task.isAllAlphabets("xyzklsadfl")
task.isAllAlphabets("code2Solve")
task.isAllAlphabets("sdxfsd-cf")
task.isAllAlphabets("kalkicode")
task.isAllAlphabets("FiveDiv")
if __name__ == "__main__": main()
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
# Ruby program for
# Check if a string contains only alphabets
class Alphabets
def isAllAlphabets(text)
n = text.length
if (n == 0)
# Empty String
return
end
print("\n Given text : ", text)
i = 0
while (i < n)
if (text[i] >= 'a' && text[i] <= 'z' ||
(text[i] >= 'A' && text[i] <= 'Z'))
# When alphabets occurs
i += 1
else
print("\n No ")
return
end
end
# When all alphabets character
print("\n Yes ")
end
end
def main()
task = Alphabets.new()
# Test
task.isAllAlphabets("xyzklsadfl")
task.isAllAlphabets("code2Solve")
task.isAllAlphabets("sdxfsd-cf")
task.isAllAlphabets("kalkicode")
task.isAllAlphabets("FiveDiv")
end
main()
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
import scala.collection.mutable._;
// Scala program for
// Check if a string contains only alphabets
class Alphabets()
{
def isAllAlphabets(text: String): Unit = {
var n: Int = text.length();
if (n == 0)
{
// Empty String
return;
}
print("\n Given text : " + text);
var i: Int = 0;
while (i < n)
{
if (text.charAt(i) >= 'a' && text.charAt(i) <= 'z' ||
(text.charAt(i) >= 'A' && text.charAt(i) <= 'Z'))
{
// When alphabets occurs
i += 1;
}
else
{
print("\n No ");
return;
}
}
// When all alphabets character
print("\n Yes ");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: Alphabets = new Alphabets();
// Test
task.isAllAlphabets("xyzklsadfl");
task.isAllAlphabets("code2Solve");
task.isAllAlphabets("sdxfsd-cf");
task.isAllAlphabets("kalkicode");
task.isAllAlphabets("FiveDiv");
}
}
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
import Foundation;
// Swift 4 program for
// Check if a string contains only alphabets
class Alphabets
{
func isAllAlphabets(_ data: String)
{
let text = Array(data);
let n: Int = text.count;
if (n == 0)
{
// Empty String
return;
}
print("\n Given text : ", data, terminator: "");
var i: Int = 0;
while (i < n)
{
if (text[i] >= "a" && text[i] <= "z" ||
(text[i] >= "A" && text[i] <= "Z"))
{
// When alphabets occurs
i += 1;
}
else
{
print("\n No ", terminator: "");
return;
}
}
// When all alphabets character
print("\n Yes ", terminator: "");
}
}
func main()
{
let task: Alphabets = Alphabets();
// Test
task.isAllAlphabets("xyzklsadfl");
task.isAllAlphabets("code2Solve");
task.isAllAlphabets("sdxfsd-cf");
task.isAllAlphabets("kalkicode");
task.isAllAlphabets("FiveDiv");
}
main();
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
// Kotlin program for
// Check if a string contains only alphabets
class Alphabets
{
fun isAllAlphabets(text: String): Unit
{
val n: Int = text.length;
if (n == 0)
{
// Empty String
return;
}
print("\n Given text : " + text);
var i: Int = 0;
while (i < n)
{
if (text.get(i) >= 'a' && text.get(i) <= 'z' ||
(text.get(i) >= 'A' && text.get(i) <= 'Z'))
{
// When alphabets occurs
i += 1;
}
else
{
print("\n No ");
return;
}
}
// When all alphabets character
print("\n Yes ");
}
}
fun main(args: Array < String > ): Unit
{
val task: Alphabets = Alphabets();
// Test
task.isAllAlphabets("xyzklsadfl");
task.isAllAlphabets("code2Solve");
task.isAllAlphabets("sdxfsd-cf");
task.isAllAlphabets("kalkicode");
task.isAllAlphabets("FiveDiv");
}
Output
Given text : xyzklsadfl
Yes
Given text : code2Solve
No
Given text : sdxfsd-cf
No
Given text : kalkicode
Yes
Given text : FiveDiv
Yes
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment