Exercise
Function IsAlphabetic
Objetive
Write a Visual Basic (VB.Net) function that tells if a character is alphabetic (A through Z) or not. It should be used like this:
if (IsAlphabetic ("a"))
System.Console.WriteLine ("It is an alphabetic character");
(Note: do not worry about accents and ñ)
Code
Imports System
Public Class exercise123
Public Shared Function IsAlpha(ByVal simbolo As Char) As Boolean
If (simbolo >= "a"c) AndAlso (simbolo <= "z"c) Then Return True
If (simbolo >= "A"c) AndAlso (simbolo <= "Z"c) Then Return True
Return False
End Function
Public Shared Function IsAlpha2(ByVal simbolo As Char) As Boolean
simbolo = Char.ToLower(simbolo)
If (simbolo >= "a"c) AndAlso (simbolo <= "z"c) Then Return True
Return False
End Function
Public Shared Function IsAlpha3(ByVal simbolo As Char) As Boolean
simbolo = simbolo.ToString().ToLower()(0)
If (simbolo >= "a"c) AndAlso (simbolo <= "z"c) Then Return True
Return False
End Function
Public Shared Function IsAlpha4(ByVal simbolo As Char) As Boolean
Dim validas As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqwrstuvwxyz"
If validas.Contains(simbolo) Then Return True
Return False
End Function
Public Shared Sub Main()
Console.WriteLine(IsAlpha("w"c))
Console.WriteLine(IsAlpha("2"c))
End Sub
End Class