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