开发者

Padding problem for text email using PadRight in C#

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

Pa开发者_如何学JAVAyment Method : VISA


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:

Padding problem for text email using PadRight in C#

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜