Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Char operations (Is Digit, Is Lower and Is Upper) using “Char Class” in C# (.net 2.0) PART1.

Author: Zunnair
Download Source Code : 862_source.zip

In this article you will learn that how we can check that character is digit, in lower case and in upper case using “Char Class” in C# and VB (.net 2.0).

 

“Char class” is a class which dot net provides us to perform different operations with characters.
Is Digit:
To check that a given character is a digit or not char class provides us a function named is Digit ().
This function has one overloaded method. In first method it takes a character as a parameter and returns Boolean value (True/False). If value is digit than it returns true else it returns false.
To demonstrate make a window application. Drag two text boxes and one button on the form. Write character in first text box than press button. You will get the result in second text box.
Now write the following code on button click event
C#
private void btn_isdigit_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value1.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsDigit(str[0]);
                txt_isdigit.Text = b.ToString();
            }
           
        }
VB
Private Sub btn_isdigit_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value1.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = [Char].IsDigit(str(0))
            txt_isdigit.Text = b.ToString()
 
        End If
    End Sub
In the overloaded method this function takes string and an index value as a parameter and tells that the character on the given index is digit or not.
Now write the following code on button click event
C#
private void btn_isdigit_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value1.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsDigit(str,0);
                txt_isdigit.Text = b.ToString();
            }
           
        }
VB
Private Sub btn_isdigit_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value1.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = [Char].IsDigit(str,0)
            txt_isdigit.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is digit or not.
Is Lower:
To check that a given character is in lower case or not char class provides us a function named is lower ().
This function also has one overloaded method. In first method it takes a character as a parameter and returns Boolean value (True/False). If value is in lower case than it returns true else it returns false.
To demonstrate make a window application. Drag two text boxes and one button on the form. Write character in first text box than press button. You will get the result in second text box.
Now write the following code on button click event
C#
private void btn_islower_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value2.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsLower(str[0]);
                txt_islower.Text = b.ToString();
            }
        }
VB
Private Sub btn_islower_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value2.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = [Char].IsLower(str(0))
            txt_islower.Text = b.ToString()
        End If
    End Sub
In the overloaded method this function takes string and an index value as a parameter and tells that the character on the given index is in lower case or not.
Now write the following code on button click event
C#
private void btn_islower_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value2.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsLower(str,0);
                txt_islower.Text = b.ToString();
            }
        }
VB
Private Sub btn_islower_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value2.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = [Char].IsLower(str,0)
            txt_islower.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is lower or not.
 
Is Upper:
To check that a given character is in Upper case or not char class provides us a function named is Upper ().
This function also has one overloaded method. In first method it takes a character as a parameter and returns Boolean value (True/False). If value is in upper case than it returns true else it returns false.
To demonstrate make a window application. Drag two text boxes and one button on the form. Write character in first text box than press button. You will get the result in second text box.
Now write the following code on button click event
C#
private void btn_isupper_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value3.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsUpper(str[0]);
               txt_isupper.Text= b.ToString();
            }
        }
VB
Private Sub btn_isupper_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value3.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = [Char].IsUpper(str(0))
            txt_isupper.Text = b.ToString()
        End If
    End Sub
In the overloaded method this function takes string and an index value as a parameter and tells that the character on the given index is in Upper case or not.
Now write the following code on button click event
C#
private void btn_isupper_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value3.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsUpper(str,0);
               txt_isupper.Text= b.ToString();
            }
        }
VB
Private Sub btn_isupper_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value3.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = [Char].IsUpper(str,0)
            txt_isupper.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is upper or not.
Now write the following code on FORM LOAD event:
C#
private void Form1_Load(object sender, EventArgs e)
        {
 
            this.Text = "Devasp.net Application";
        }
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
 
        Me.Text = "Devasp.net Application"
 End Sub
 
This simple article tells how we can check that character is digit, in lower case and in upper case using “Char Class” in C# and VB (.net 2.0).

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to get full path of current directory of process (from where process starts) and get/set the exit code of your process using “Environment Class” in C# (.net 2.0).

Disclaimer - Privacy
© 2002-2017 DevASP.net