Have a LINQ result, need to format it in plain text nicely to send by email.
For example each record contains “ProductName”, “SalesAmount”, “Taxes”
And product names could be strings different length for different records.
Need to format a list of such records as plaintext table. Using “———-” as horizontal line and “|” as vertical line.
As you don’t know the max size of product name you don’t know the size of vertical line in characters for it. Suppose need to find the maximum product name length and depending on it calculate amount of “-” characters needed. But is there anything that can auto format?
Assuming that font is mono-spaced.
What is the best way to do it?
Thanks.
What you may be looking for is the alignment parameter in a format string. I.e.:
will render in three equal columns, left-aligned (right-aligned when you remove the minus sign) on 20 characters each. Use this to make nice columns in text-only with your data.
After your edit:
The above will output the following (replace the notorious Col1, Col2 with your properties, like Name, Address etc):