Many times its required to convert a string into an array. In this tutorial I will show how to convert a string into an array.
First take a textbox names TextBox1 and a button to convert it into array. Also take a label to show the result.
On the button click event write the following code..
First take a textbox names TextBox1 and a button to convert it into array. Also take a label to show the result.
On the button click event write the following code..
private void button1_Click_1(object sender, EventArgs e)
{
char []name ;
int i = 0;
int count = 0;
/* Converting string into array */
name = textBox1.Text.ToArray();
/* Using for loop */
for (i = 0; i < name.Length;i++ )
{
label1.Text = label1.Text + Convert.ToString(name[i]);
}
/* Using foreach loop */
foreach (char a in name) { label1.Content = label1.Content + Convert.ToString(name[i]); }
}
0 comments:
Post a Comment