我想用它们各自的html实体替换版权符号的实例。现在,版权符号只是直接复制到产品名称中,所以现在,当我发送完整订单摘要的电子邮件时,版权符号显示为“?”。代替。我需要在字符串中查找(c),(R)和TM版权符号,并用适当的HTML实体代码替换每个符号。但是,我不知道如何做这样的String.Replace()(搜索3个字符,并用3个新值替换它们看起来很复杂)用3个新值替换字符串中的3个字符
这里是设置电子邮件消息的代码(现在我只检查了(R)标志):
protected void sendEmail()
{
Item CurrentItem = Sitecore.Context.Item;
Item HomeItem = ScHelper.FindAncestor(CurrentItem, "gojoOrderReview");
if (HomeItem != null)
{
TextBox rTxt = (TextBox)FindControl("rEmail");
TextBox fName = (TextBox)FindControl("yName");
Literal lit = (Literal)FindControl("emailTbl");
//string html = lit.Text;
try
{
//.Value = string.Format("<tr><td style="width:80px;">{0}</td><td style="width:50px;">{1}</td><td style="width:20px;>{2}</td><td style="width:20px;>{3}</td><td style="width:60px;>{4}</td></tr>", SkuItem.Fields["Order Number"].Value, SkuItem.Fields["Description"].Value, qtyAmt);
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(rTxt.Text);
msg.Subject = "GOJO product order summary";
msg.From = new System.Net.Mail.MailAddress("[email protected]");
msg.Body = "Here is a list of the products your friend, " + fName.Text + ", has selected: ";
msg.IsBodyHtml = true;
msg.Body += "<h1></h1>";
msg.Body += "<table cellpadding='4' cellspacing='0' border='1px solid black' style='padding: 4px 0 4px 0; border-collapse: collapse; width:750px; text-align: left; font-family: sans-serif;'><tr><th></th><th>Product</th><th>GOJO SKU</th><th>Size</th><th>Case Pack</th><th>Quantity</th></tr>";
msg.Body += lit.Text.ToString().Replace("®", "®") +"</table>";
System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient("mail.innismaggiore.com");
sc.Send(msg);
}
catch (Exception EX)
{
GOJOHelper.WriteLog("GOJO Order Review - sendEmail()", EX.ToString());
}
}
}
这里是创建点燃变量的文本值的代码:
lit.Text += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>", drow["Thumbnail"], CPNItem["Complete Name"], marketItem.Fields["SKU"].Value, drow["Size"].ToString(), marketItem.Fields["Case Pack"].Value, qtys.ToString());
您只需链通话与string.replace。正则表达式会比这些问题值得的更麻烦。 – Casey
您不应链接'String.Replace'调用,因为每个调用都会迭代原始字符串来创建一个新字符串。 –
考虑使用'StringBuilder'来构建主体。每个字符串** + = **连接会产生一个新的字符串。 –