Hello,
I'm a beginner to C# programming and working on some exercises. I have
form where a user enters their name and when they click on a button it
parses their name and puts it on 3 seperate lines. Problem is I'm not
sure how to get this to work if the person only enters their first and
last name. I have it working fine if they enter their first, middle,
and last name. Can someone provide some sample code to get this to
work if the user only enters their first and last name or point me in
the right direction? Below is the code:
private void btnParseName_Click(object sender, System.EventArgs e)
{
string fullName = txtFullName.Text;
fullName = fullName.Trim();
string[] names = fullName.Split(' ');
string firstName = names[0];
string middleName = names[1];
string lastName = names[2];
MessageBox.Show("First Name:\t" + firstName + "\n\n" +
"Middle Name:\t" + middleName + "\n\n" +
"Last Name:\t" + lastName + "\n", "Parse Name");
}
Thanks