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 (To Lower, To Upper, To String, Try Parse) using “Char Class” in C# (.net 2.0) PART5.

Author: Zunnair
Download Source Code : 868_source.zip

In this article you will learn that how we can convert a character to lower case, upper case, string and convert string to Unicode character 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.
Try Parse:
To convert the string in its equivalent Unicode character char class provides us a function named Try Parse ().
This function takes a string and character as a parameter and returns Boolean value (True/False). If value converted successfully 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 string 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_Try_parse_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value3.Text;
            bool b;
            Char a;
            if (str != string.Empty)
            {
                b = Char.TryParse(str, out a);
                txt_Result3.Text = b.ToString();
            }
        }
VB
Private Sub btn_Try_parse_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value3.Text
        Dim b As Boolean
        Dim a As [Char]
        If str <> String.Empty Then
            b = [Char].TryParse(str, a)
            txt_Result3.Text = b.ToString()
        End If
    End Sub
This simple code converts the string in Unicode and returns true if conversion is successfully done.
To Lower:
To convert the Upper Case character in Lower case character char class provides us a function named To Lower ().
This function takes a character as a parameter and returns character after changing it in lower case.
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_Tolower_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value1.Text;
            char b;
            if (str != string.Empty)
            {
                b = Char.ToLower(str[0]);
                txt_Result1.Text = b.ToString();
            }
        }
VB
Private Sub btn_Tolower_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value1.Text
        Dim b As Char
        If str <> String.Empty Then
            b = [Char].ToLower(str(0))
 
            txt_Result1.Text = b.ToString()
        End If
    End Sub
This simple code converts the given letter in lower case.
 
To Upper:
To convert the Lower Case character in Upper case character char class provides us a function named To Upper ().
This function takes a character as a parameter and returns character after changing it in upper case.
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_ToUpper_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value2.Text;
            char b;
            if (str != string.Empty)
            {
                b = Char.ToUpper(str[0]);
                txt_Result2.Text = b.ToString();
            }
        }
VB
Private Sub btn_ToUpper_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value2.Text
        Dim b As Char
        If str <> String.Empty Then
            b = [Char].ToUpper(str(0))
            txt_Result2.Text = b.ToString()
        End If
    End Sub
This simple code converts the given letter in upper case.
To String:
To convert character in string character char class provides us a function named To String ().
This function takes a character as a parameter and returns string.
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_tostring_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_value4.Text;
            string b;
            if (str != string.Empty)
            {
                b = Char.ToString(str[0]);
                txt_Result4.Text = b;
            }
        }
VB
Private Sub btn_tostring_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_value4.Text
        Dim b As String
        If str <> String.Empty Then
            b = [Char].ToString(str(0))
            txt_Result4.Text = b
        End If
    End Sub
This simple code converts the given character in to string.
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 convert a character to lower case, upper case, string and convert string to Unicode character using “Char Class” in C# and VB (.net 2.0).
 

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Char operations (Is Symbol, is Separator, and is white space) using “Char Class” in C# (.net 2.0) PART4.

Disclaimer - Privacy
© 2002-2017 DevASP.net