0

I am trying to write inputs from different text boxes into one string. I have written the following code to create the array:

private void btnSave_Click(object sender, EventArgs e)
        {
            contents[0] = txtName.Text;
            contents[1] = txtSurname.Text;
            contents[2] = dtpDOB.Text;
            contents[3] = lblGenUsername.Text;
            contents[4] = lblPassword.Text;
        }

I want the final output to be saved onto a notepad in the following format when the data is received from the inputs:

Tim Forest 25-03-1999 u12345678 password

3
  • 4
    Have you tried anything? Seems like instead of an array it would be easier to just concatenate the string together, or use String.Format... Commented Mar 10, 2020 at 14:40
  • 1
    What have you tried so far? What issue do you face? Please also have a look on How to ask and give us a minimal code example that reproduces your issue Commented Mar 10, 2020 at 14:40
  • Take a look at the following code snippet, in my opinion is quite similar to what you are trying to achieve. codeproject.com/Questions/467339/… Commented Mar 10, 2020 at 14:42

2 Answers 2

0

This should solve your problem:

private void btnSave_Click(object sender, EventArgs e)
{
    string text = txtName.Text 
     + " " + txtName.Text
     + " " + txtSurname.Text
     + " " + dtpDOB.Text
     + " " + lblGenUsername.Text
     + " " + lblPassword.Text;
    File.WriteAllText("C:\\myFile.txt", text);
}
Sign up to request clarification or add additional context in comments.

Comments

0

If you just need the exact strings within the text boxes concatenating is the way to go.

 string text = txtName.Text 
 + " " + txtName.Text 
 + " " + txtSurname.Text
 + " " + dtpDOB.Text
 + "u" + lblGenUsername.Text
 + " " + lblPassword.Text;

to add the U and have it predefined you would have to add it before the username.

@Guillaume Ladeuille

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.