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
 

Conversion of string into character array using C# and VB in .net 2.0.

Author: Zunnair
Download Source Code : 834_CharArrayTostring.zip

In this simple article you will learn that how to you can convert string into character array.

 Create new c# project. Drag two buttons and two rich text boxes on the windows form.

 

First declare global character array

char[] characterArray;

 

Now write following code on form load event:

 

C#

private void Form1_Load(object sender, EventArgs e)

        {

            richTextBox1.Text = "Temporary Text";

            this.Text = "character Array To String";

            button1.Text = "Convert to Char Array";

            button2.Text = "Convert to String";

            button2.Enabled = false;

        }

 

VB

 

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        richTextBox1.Text = "Temporary Text"

        Me.Text = "character Array To String"

        button1.Text = "Convert to Char Array"

        button2.Text = "Convert to String"

        button2.Enabled = False

    End Sub

 

Now write code on buttons events

 

C#

 

private void button1_Click(object sender, EventArgs e)

        {

            if (richTextBox1.Text.ToString().Length > 0)

            {

                button2.Enabled = true;

               

                characterArray = richTextBox1.Text.ToCharArray();

                richTextBox2.Text = "";

 

                for (int i = 0; i < characterArray.Length; i++)

                    richTextBox2.Text += characterArray[i].ToString();

            }

        }

 

        private void button2_Click(object sender, EventArgs e)

        {

            richTextBox1.Text = "";

            for (int i = 0; i < characterArray.Length; i++)

                richTextBox1.Text += characterArray[i].ToString();

        }

VB

 

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        If richTextBox1.Text.ToString().Length > 0 Then

            button2.Enabled = True

 

            characterArray = richTextBox1.Text.ToCharArray()

            richTextBox2.Text = ""

 

            For i As Integer = 0 To characterArray.Length - 1

                richTextBox2.Text += characterArray(i).ToString()

            Next

        End If

    End Sub

 

    Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)

        richTextBox1.Text = ""

        For i As Integer = 0 To characterArray.Length - 1

            richTextBox1.Text += characterArray(i).ToString()

        Next

    End Sub

 

This is the way to use character array in efficient manner.

Article Comments
how to convert character and integer?
as -i given the input in textbox character type
given the character length without use the length () method.

Posted on 1/20/2010 8:58:21 AM by rajesh singh

convert.tointeger ( "123")

Posted on 2/23/2010 9:12:26 PM by asd

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get and set value in Syste.Collection.BitArray using C# in .net 2.0.

Disclaimer - Privacy
© 2002-2017 DevASP.net