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 Symbol, is Separator, and is white space) using “Char Class” in C# (.net 2.0) PART4.

Author: Zunnair
Download Source Code : 867_source.zip

In this article you will learn that how we can check that character is symbol, number and is white space 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 Symbol:
To check that a given character is symbol or not char class provides us a function named is Symbol ().
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 symbol 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_isSymbol_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value1.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsSymbol(str[0]);
                txt_Result1.Text = b.ToString();
            }
        }
VB
Private Sub btn_isSymbol_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].IsSymbol(str(0))
            txt_Result1.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 Symbol or not.
Now write the following code on button click event
C#
private void btn_isSymbol_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value1.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsSymbol(str, 0);
                txt_Result1.Text = b.ToString();
            }
        }
VB
Private Sub btn_isSymbol_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].IsSymbol(str, 0)
            txt_Result1.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is symbol or not.
Is Separator:
To check that a given character is separator or not char class provides us a function named is Separator ().
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 separator 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_Seperator_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value2.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsSeparator(str[0]);
                txt_Result2.Text = b.ToString();
            }
        }
VB
Private Sub btn_Seperator_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].IsSeparator(str(0))
            txt_Result2.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 separator or not.
Now write the following code on button click event
C#
private void btn_Seperator_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value2.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsSeparator(str, 0);
                txt_Result2.Text = b.ToString();
            }
        }
VB
Private Sub btn_Seperator_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].IsSeparator(str, 0)
            txt_Result2.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is separator or not.
 
Is white space:
To check that a given character is white space or not char class provides us a function named is White Space ().
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 white space 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_Space_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value3.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsWhiteSpace(str[0]);
                txt_Result3.Text = b.ToString();
            }
        }      
VB
Private Sub btn_Space_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].IsWhiteSpace(str(0))
            txt_Result3.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 white space or not.
Now write the following code on button click event
C#
private void btn_Space_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value3.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsWhiteSpace(str, 0);
                txt_Result3.Text = b.ToString();
            }
        }      
VB
Private Sub btn_Space_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].IsWhiteSpace(str, 0)
            txt_Result3.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is white space 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 that how we can check that character is symbol, number and is white space using “Char Class” in C# and VB (.net 2.0).

 

Article Comments
Thanks A loTT
really appericiatable,cos it helped me a lot!!!!!!!

Posted on 8/6/2009 1:08:33 AM by Ashish Rajput

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to Terminate process using exit code and getting new line string define for you environment using “Environment Class” in C# (.net 2.0).

Disclaimer - Privacy
© 2002-2017 DevASP.net