C# 在.NET中的字符串之间放置换行符
我使用以下c代码通过我的应用程序发送电子邮件# 但我收到的邮件是“SheerazahmedShehzorehydrabadsheerashadrabadsindhpakistan03453594552034598750258741”表格_1@hotmail.comsingle“即合并所有值,我希望textboxt的每个值都在一个单独的新行中,即C# 在.NET中的字符串之间放置换行符,c#,C#,我使用以下c代码通过我的应用程序发送电子邮件# 但我收到的邮件是“SheerazahmedShehzorehydrabadsheerashadrabadsindhpakistan03453594552034598750258741”表格_1@hotmail.comsingle“即合并所有值,我希望textboxt的每个值都在一个单独的新行中,即 Sheeraz Ahmed Shehzore Hyderabad 等等 或者更好地使用stringbuilder或string.Format Str
Sheeraz Ahmed
Shehzore
Hyderabad
等等
或者更好地使用stringbuilder或string.Format
StringBuilder bodyBuilder = new StringBuilder("");
bodyBuilder .AppendLine(TextBox1.Text);
bodyBuilder .AppendLine(txtName.Text);
bodyBuilder .AppendLine(txtCName.Text);
bodyBuilder .AppendLine(txtAddress.Text);
// etc.
myMail.Body = bodyBuilder .ToString();
或
将String.Format与Environment.NewLine结合使用 e、 g 您只需在Environment.NewLine的字符串中定义一个占位符,就可以重用它
result = text1 + Environment.NewLine + text2 + Environment.NewLine + text3;
这将把text1、text2和text3放在一个单独的行中
myMail.Body = TextBox1.Text + Environment.NewLine +
txtName.Text+ Environment.NewLine +
txtCName.Text+ Environment.NewLine +
txtAddress.Text+ Environment.NewLine +
TextBox1.Text+ Environment.NewLine +
txtCity.Text+ Environment.NewLine +
txtState.Text+ Environment.NewLine +
txtCountry.Text+ Environment.NewLine +
txtPhone.Text+ Environment.NewLine +
Fax.Text+ Environment.NewLine +
txtCell.Text+ Environment.NewLine +
txtEmail.Text+ Environment.NewLine +
txtPrinting.Text;
myMail.BodyEncoding = System.Text.Encoding.UTF8;
StringBuilder bodyBuilder = new StringBuilder("");
bodyBuilder .AppendLine(TextBox1.Text);
bodyBuilder .AppendLine(txtName.Text);
bodyBuilder .AppendLine(txtCName.Text);
bodyBuilder .AppendLine(txtAddress.Text);
// etc.
myMail.Body = bodyBuilder .ToString();
myMail.Body = String.Format("{0}{1}{2}{1}{3}{1} ... ", TextBox1.Text, Environment.NewLine, txtCName.Text, txtAddress.Text -- etc...
myMail.Body = TextBox1.Text+ Environment.NewLine +
txtName.Text+ Environment.NewLine +
txtCName.Text+ Environment.NewLine +
txtAddress.Text+ Environment.NewLine +
TextBox1.Text+ Environment.NewLine +
txtCity.Text+ Environment.NewLine +
txtState.Text+ Environment.NewLine +
txtCountry.Text+ Environment.NewLine +
txtPhone.Text+ Environment.NewLine +
Fax.Text+ Environment.NewLine +
txtCell.Text+ Environment.NewLine +
txtEmail.Text+ Environment.NewLine +
txtPrinting.Text;
String.Format("{0}{1}{2}{1}{3}", "ValueOfTextbox1", Environment.NewLine, "ValueOfTextbox2", "ValueOfTextbox3");
result = text1 + Environment.NewLine + text2 + Environment.NewLine + text3;