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 high surrogate, is low surrogate, is letter and is letter or digit) using “Char Class” in C# (.net 2.0) PART2.

Author: Zunnair
Download Source Code : 863_source.zip

In this article you will learn that how we can check that character is high surrogate, is low surrogate, is letter and is letter or digit 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 High Surrogate:
To check that a given character is high surrogate or not char class provides us a function named is High 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 high 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_ishighsurrogate_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value1.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsHighSurrogate(str[0]);
                txt_Result1.Text = b.ToString();
            }          
        }
VB
Private Sub btn_ishighsurrogate_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].IsHighSurrogate(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 High Surrogate or not.
Now write the following code on button click event
C#
private void btn_ishighsurrogate_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value1.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsHighSurrogate(str,0);
                txt_Result1.Text = b.ToString();
            }          
        }
VB
Private Sub btn_ishighsurrogate_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].IsHighSurrogate(str, 0)
            txt_Result1.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is high surrogate or not.
Is Low Surrogate:
To check that a given character is low surrogate or not char class provides us a function named is low surrogate ().
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 low 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_islowsurrogate_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value3.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsLowSurrogate(str[0]);
               txt_Result3.Text = b.ToString();
            }
        }
VB
Private Sub btn_islowsurrogate_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].IsLowSurrogate(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 low surrogate or not.
Now write the following code on button click event
C#
private void btn_islowsurrogate_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value3.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsLowSurrogate(str,0);
               txt_Result3.Text = b.ToString();
            }
        }
VB
Private Sub btn_islowsurrogate_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].IsLowSurrogate(str,0)
            txt_Result3.Text = b.ToString()
        End If
End Sub
This simple code checks that character is low surrogate or not.
Is Letter:
To check that a given character is letter or not char class provides us a function named is Latter ().
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 letter 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_Letter_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value2.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsLetter(str[0]);
                txt_Result2.Text = b.ToString();
            }
        }
VB
Private Sub btn_Letter_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].IsLetter(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 letter or not.
Now write the following code on button click event
C#
private void btn_Letter_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value2.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsLetter(str, 0);
                txt_Result2.Text = b.ToString();
            }
        }
VB
Private Sub btn_Letter_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].IsLetter(str, 0)
            txt_Result2.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is letter or not.
Is Letter Or Digit:
To check that a given character is letter/digit or not char class provides us a function named is Latter ().
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 letter/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_letter_or_digit_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value4.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsLetterOrDigit(str[0]);
                txt_Result4.Text = b.ToString();
            }
        }
VB
Private Sub btn_letter_or_digit_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value4.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = [Char].IsLetterOrDigit(str(0))
            txt_Result4.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 letter/digit or not.
Now write the following code on button click event
C#
private void btn_letter_or_digit_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value4.Text;
            bool b;
            if (str != string.Empty)
            {
                b = Char.IsLetterOrDigit(str, 0);
                txt_Result4.Text = b.ToString();
            }
        }
VB
Private Sub btn_letter_or_digit_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value4.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = [Char].IsLetterOrDigit(str, 0)
            txt_Result4.Text = b.ToString()
        End If
    End Sub
This simple code checks that character is letter/digit 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 high surrogate, is low surrogate, is letter and is letter or digit using “Char Class” in C# and VB (.net 2.0).

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Char operations (Is Digit, Is Lower and Is Upper) using “Char Class” in C# (.net 2.0) PART1.

Disclaimer - Privacy
© 2002-2017 DevASP.net