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 surrogate, is number, and is punctuation) using “Char Class” in C# (.net 2.0) PART3.

Author: Zunnair
Download Source Code : 865_source.zip

In this article you will learn that how we can check that character is surrogate, is number, and is punctuation 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 Surrogate:
To check that a given character is surrogate or not char class provides us a function named is Surrogate ().
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 surrogate 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_issurrogate_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value1.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsSurrogate(str[0]);
                txt_Result1.Text = b.ToString();
            }
        }
VB
Private Sub btn_issurrogate_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].IsSurrogate(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 Surrogate or not.
Now write the following code on button click event
C#
private void btn_issurrogate_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value1.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsSurrogate(str, 0);
                txt_Result1.Text = b.ToString();
            }
        }
VB
Private Sub btn_issurrogate_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].IsSurrogate(str, 0)
            txt_Result1.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is surrogate or not.
Is Number:
To check that a given character is number or not char class provides us a function named is Number ().
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 number 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_number_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value2.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsNumber(str[0]);
                txt_Result2.Text = b.ToString();
            }
        }
VB
Private Sub btn_number_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].IsNumber(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 number or not.
Now write the following code on button click event
C#
private void btn_number_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value2.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsNumber(str, 0);
                txt_Result2.Text = b.ToString();
            }
        }
VB
Private Sub btn_number_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].IsNumber(str, 0)
            txt_Result2.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is low surrogate or not.
 
Is Punctuation:
To check that a given character is punctuation or not char class provides us a function named is Punctuation ().
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 punctuation 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_punctuation_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value3.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsPunctuation(str[0]);
                txt_Result3.Text = b.ToString();
            }
        }
VB
Private Sub btn_punctuation_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].IsPunctuation(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 punctuation or not.
Now write the following code on button click event
C#
private void btn_punctuation_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value3.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsPunctuation(str, 0);
                txt_Result3.Text = b.ToString();
            }
        }
VB
Private Sub btn_punctuation_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].IsPunctuation(str, 0)
            txt_Result3.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is punctuation 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 surrogate, is number, and is punctuation using “Char Class” in C# and VB (.net 2.0).
   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to Get and Set values of environment variables using “Environment Class” in C# (.net 2.0).

Disclaimer - Privacy
© 2002-2017 DevASP.net