reading some string from a text file and the writing them to a text file there only a small problem and that's with the alignment of the text. The {4} parameter is what needs to be formatted to the right so that they are all vertically aligned.
while (recordIn != null)
{
fields = recordIn.Split(DELIM);
emp.accNumber = Convert.ToInt32(fields[0]);
emp.lastName = fields[1];
emp.firstName = fields[2];
emp.funds = Convert.ToDouble(fields[3]);
double money = Convert.ToDouble(fields[3].ToString());
if (money < 0)
{
Console.WriteLine("{0},{1},{2}, {3, 2}, {4}", emp.accNumber, emp.lastName, emp.firstName, emp.funds.ToString("F2"), creditOutput);
}
else
{
Console.WriteLine("{0},{1},{2}, {3, 2} {4}", emp.accNumber, emp.lastName, emp.firstName, emp.funds.ToString("F2"), debitOutput);
}
recordIn = reader.ReadLine();
}
You can try string.PadLeft or string.PadRight
Also you can do it like this:
To align string to the left (spaces on the right) use formatting patern with comma (,) followed by a negative number of characters: String.Format("{0,–10}", text). To right alignment use a positive number: {0,10}.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With