C# 中使用 PadRight 的文本电子邮件填充问题
我有一个关于使用 C# .net 对文本电子邮件进行编码的问题,因为我有简单的 ASCII,但是当我进行填充以格式化用户的收据时,数据没有对齐,尽管当我检查 NotePad++ 中的行时,它们是完全一致的相同的字符数。下面是一些代码,谁能告诉我我做错了什么?
StringBuilder oSB = new StringBuilder(); oSB.AppendLine(EmailLine("金额", oTrans.PaymentAmount.ToString())); oSB.AppendLine(EmailLine("付款方式", oTrans.CardType)); 私有静态字符串EmailLine(字符串FieldLabel,字符串FieldVal) { 返回 PadLabel(FieldLabel) + FieldVal ; } 私有静态字符串PadLabel(字符串FieldLabel) { return FieldLabel.PadRight(40, char.Parse(" ")) + ": "; 我的输出如下
所示:
金额:100.00
付款方式:VISA
I have a question regarding encoding for text email messages using C# .net because I have mine as simple ASCII but when doing padding for formatting a recipt to the user the data is not lining up although when I check the lines in say NotePad++ they are exactly the same No. of character. Below is some code, can anyone tell me what I'm doing wrong?
StringBuilder oSB = new StringBuilder();
oSB.AppendLine(EmailLine("Amount", oTrans.PaymentAmount.ToString()));
oSB.AppendLine(EmailLine("Payment Method", oTrans.CardType));
private static string EmailLine(string FieldLabel, string FieldVal)
{
return PadLabel(FieldLabel) + FieldVal ;
}
private static string PadLabel(string FieldLabel)
{
return FieldLabel.PadRight(40, char.Parse(" ")) + ": ";
}
My output looks like this:
Amount : 100.00
Payment Method : VISA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们是否对齐取决于用于显示电子邮件的字体。这是电子邮件客户端上的设置。例如,我在 Outlook 中设置它的位置:
尝试将 Notepad++ 中的字体更改为 Times new Roman 和快递员和你会发现他们的排队方式不同。
如果您将其作为计划文本邮件发送,则您无法控制用户的字体。您可以做的最好的事情是指示“最好使用___字体阅读”或将其格式化为HTML,您可以在其中进行一些控制。
其他选项包括将其输出到 PDF 文件或图像(同样您拥有更多控制权)。
Whether or not they line up will depend on the font being used to display the email. That's a setting on the email client. For example, here is where I would set it in Outlook:
Try changing the font in Notepad++ to Times new Roman and Courier and you'll see that they line up differently.
You have no control over the user's font if you're sending it as a plan text mail. The best you can do it indicate "Best read with ___ font" or format it as HTML where you have some control.
Other options would include outputting this to a PDF file, or an image (again where you have more control).