【问题标题】:How can I add line break tag before for txtmessage.Text?如何在文本 message.Text 之前添加换行标记?
【发布时间】:2016-09-19 05:50:39
【问题描述】:
mail.Body = "your appointment has been scheduled on :" + txtappointment.Text + " " + txtmessage.Text;

【问题讨论】:

  • 您要换行(
    )还是换行?
  • 换行哥

标签: html email c#-4.0 line-breaks


【解决方案1】:

试试这个

mail.Body ="your appointment has been scheduled on :"+ <br> + txtappointment.Text +" "+ txtmessage.Text;

【讨论】:

  • 我想在“txtmessage.text”之前添加中断标签;
  • 我期望输出是 ::您的约会已安排在 29-9-2016 下一行早上 10:00am
【解决方案2】:

对于新行,您应该使用\n。或者看看这个较早的帖子: Adding a newline into a string in C#

【讨论】:

    【解决方案3】:

    你可以试试这个+Environment.NewLine+

    mail.Body ="your appointment has been scheduled on :"+ <br> + txtappointment.Text +System.Environment.NewLine+ txtmessage.Text;
    

    【讨论】:

      【解决方案4】:

      这是您的问题解决方案的示例,请尝试一次,您的答案在我的代码段中的评论中。

      //mail.Body ="your appointment has been scheduled on :"+ txtappointment.Text +"\n"+ txtmessage.Text;
      var Fname = "samudrala";
      var Lname = "Raamu";
      alert(Fname+"\n"+Lname);

      【讨论】:

      • 正确代码是::mail.Body ="您的约会已安排在:"+ txtappointment.Text +"\n"+ txtmessage.Text;
      • 给你发邮件兄弟...任何疑问我都在问你
      • 也使用mail.Body ="你的约会已经安排在:"+ txtappointment.Text +'
        '+ txtmessage.Text;这是动态添加一个 html 标记,它是断行的,但纯 javascript 它不正确,我们可以用户“\n”是正确的
      • samudrala.ramu145@gmail.com
      • 如何添加 textcolor 兄弟
      【解决方案5】:

      根据您的 cmets,您需要这样的东西(并且您应该使用 string.Format 方法来轻松管理字符串:

      mail.Body = string.format("your appointment has been scheduled on: {0}<br/>{1}", txtappointment.Text, txtmessage.Text);
      

      您可以看到文本编辑器文本的占位符,第一个用于约会,第二个用于消息。要使 html 正常工作,您必须为此设置 IsBodyHtml 标志:

      mail.IsBodyHtml = true;
      

      如果您的电子邮件客户端不支持 html 或者您不希望它是 html,请使用 Environment.NewLine 常量,正如 @AsifuzzamanRedoy 建议的那样:

      mail.Body = string.format("your appointment has been scheduled on: {0}{2}{1}", txtappointment.Text, txtmessage.Text, Environment.NewLine);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-27
        • 2021-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-17
        相关资源
        最近更新 更多