this is the program
string[] words = TextBox1.Text.Split(' ');
string fName = words[0];
string lName = words[1];
TextBox2.Text = fName.ToString();
TextBox3.Text = lName.ToString();
i split the two word using space , but in a single word it have some error like "Index was outside the bounds of the array." then how to solve it
Using split() method in c# , i split the word using space
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.


Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted Nov 19, 2012, 8:01 PM EST
string fName=string.Empty;
string lName = string.Empty;
string[] words = TextBox1.Text.Split(' ');
if (words.Length >= 2)
{
fName = words[0];
lName = words[1];
}
else
{
fName = words[0];
}
TextBox2.Text = fName.ToString();
TextBox3.Text = lName.ToString();