我想用它們各自的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'來構建主體。每個字符串** + = **連接會產生一個新的字符串。 –