文本文件已保存。在记事本中打开时,行是缩进的。不确定这是为什么?
Text file saved. When opened in Notepad, lines are indented. Unsure of why that is?
代码:
private void HomeSavebtn_Click(object sender, EventArgs e)
{
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string line = string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15} {16} {17} {18} {19} {20}" +
"{21} {22} {23} {24} {25} {26} {27} {28} {29} {30} {31} {32} {33} {34} {35} {36} {37} {38} {39}"
, txtFirstNamedInsured.Text + Environment.NewLine // {0}
, comboOccupation.Text + Environment.NewLine // {1}
, comboEducation.Text + Environment.NewLine // {2}
, txtBirthDate.Text + Environment.NewLine // {3}
, txtSocial.Text + Environment.NewLine // {4}
, comboGender.Text + Environment.NewLine // {5}
, txtLicense.Text + Environment.NewLine // {6}
, comboMaritalStatus.Text + Environment.NewLine // {7}
, txtAddress.Text + Environment.NewLine // {8}
, txtNewAddress.Text + Environment.NewLine // {9}
, txtSecondNamedInsured.Text + Environment.NewLine //{10}
, comboOccupation2.Text + Environment.NewLine // {11}
, comboEducation2.Text + Environment.NewLine // {12}
, txtBirthDate2.Text + Environment.NewLine // {13}
, txtSocial2.Text + Environment.NewLine // {14}
, comboGender2.Text + Environment.NewLine // {15}
, txtLicense2.Text + Environment.NewLine // {16}
, comboMaritalStatus2.Text + Environment.NewLine // {17}
, comboRelationToInsured.Text // {18}
, comboYearBuilt.Text + Environment.NewLine // {19}
, comboHomeStyle.Text + Environment.NewLine // {20}
, txtAcres.Text + Environment.NewLine // {21}
, comboUseType.Text + Environment.NewLine // {22}
, comboSiding.Text + Environment.NewLine // {23}
, comboPrimaryHeat.Text + Environment.NewLine // {24}
, comboSecondaryHeat.Text + Environment.NewLine // {25}
, txtSquareFeet.Text + Environment.NewLine // {26}
, comboBathroom.Text + Environment.NewLine // {27}
, comboGarage.Text + Environment.NewLine // {28}
, txtGarageSQFT.Text + Environment.NewLine // {29}
, comboRoofType.Text + Environment.NewLine // {30}
, comboRoofYear.Text + Environment.NewLine // {31}
, comboPool.Text + Environment.NewLine // {32}
, comboTramp.Text + Environment.NewLine // {33}
, comboCarrier.Text + Environment.NewLine // {34}
, txtCoverage.Text + Environment.NewLine // {35}
, txtAnnualPrem.Text + Environment.NewLine // {36}
, txtClaims.Text + Environment.NewLine // {37}
, txtPhone.Text + Environment.NewLine // {38}
, txtReferral.Text + Environment.NewLine); // {39}
File.WriteAllText(saveFileDialog1.FileName, line, Encoding.GetEncoding(1252));
}
}
// 输出创建了一个文件,一切正常,但在记事本中打开时,行随机缩进。我不确定这是为什么?
输出:Notepad Capture
这是因为 {0} {1} {2}
等之间有空格。如果删除所有空格,则不应缩进任何行。
代码: private void HomeSavebtn_Click(object sender, EventArgs e) {
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string line = string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15} {16} {17} {18} {19} {20}" +
"{21} {22} {23} {24} {25} {26} {27} {28} {29} {30} {31} {32} {33} {34} {35} {36} {37} {38} {39}"
, txtFirstNamedInsured.Text + Environment.NewLine // {0}
, comboOccupation.Text + Environment.NewLine // {1}
, comboEducation.Text + Environment.NewLine // {2}
, txtBirthDate.Text + Environment.NewLine // {3}
, txtSocial.Text + Environment.NewLine // {4}
, comboGender.Text + Environment.NewLine // {5}
, txtLicense.Text + Environment.NewLine // {6}
, comboMaritalStatus.Text + Environment.NewLine // {7}
, txtAddress.Text + Environment.NewLine // {8}
, txtNewAddress.Text + Environment.NewLine // {9}
, txtSecondNamedInsured.Text + Environment.NewLine //{10}
, comboOccupation2.Text + Environment.NewLine // {11}
, comboEducation2.Text + Environment.NewLine // {12}
, txtBirthDate2.Text + Environment.NewLine // {13}
, txtSocial2.Text + Environment.NewLine // {14}
, comboGender2.Text + Environment.NewLine // {15}
, txtLicense2.Text + Environment.NewLine // {16}
, comboMaritalStatus2.Text + Environment.NewLine // {17}
, comboRelationToInsured.Text // {18}
, comboYearBuilt.Text + Environment.NewLine // {19}
, comboHomeStyle.Text + Environment.NewLine // {20}
, txtAcres.Text + Environment.NewLine // {21}
, comboUseType.Text + Environment.NewLine // {22}
, comboSiding.Text + Environment.NewLine // {23}
, comboPrimaryHeat.Text + Environment.NewLine // {24}
, comboSecondaryHeat.Text + Environment.NewLine // {25}
, txtSquareFeet.Text + Environment.NewLine // {26}
, comboBathroom.Text + Environment.NewLine // {27}
, comboGarage.Text + Environment.NewLine // {28}
, txtGarageSQFT.Text + Environment.NewLine // {29}
, comboRoofType.Text + Environment.NewLine // {30}
, comboRoofYear.Text + Environment.NewLine // {31}
, comboPool.Text + Environment.NewLine // {32}
, comboTramp.Text + Environment.NewLine // {33}
, comboCarrier.Text + Environment.NewLine // {34}
, txtCoverage.Text + Environment.NewLine // {35}
, txtAnnualPrem.Text + Environment.NewLine // {36}
, txtClaims.Text + Environment.NewLine // {37}
, txtPhone.Text + Environment.NewLine // {38}
, txtReferral.Text + Environment.NewLine); // {39}
File.WriteAllText(saveFileDialog1.FileName, line, Encoding.GetEncoding(1252));
}
}
// 输出创建了一个文件,一切正常,但在记事本中打开时,行随机缩进。我不确定这是为什么?
输出:Notepad Capture
这是因为 {0} {1} {2}
等之间有空格。如果删除所有空格,则不应缩进任何行。