Controlling spacing
You can define the width of the string that is inserted into the result string by using syntax such as {0,12}
, which inserts a 12-character string. In this case, the string representation of the first object is right-aligned in the 12-character field. (If the string representation of the first object is more than 12 characters in length, though, the preferred field width is ignored, and the entire string is inserted into the result string.)
Controlling alignment
By default, strings are right-aligned within their field if you specify a field width. To left-align strings in a field, you preface the field width with a negative sign, such as {0,-12}
to define a 12-character right-aligned field.
For example, to pad the destination routing number to 10 characters, with the spaces at the end:
sbOAKAccp.AppendFormat("{0,-10}", dsXml.Tables["EHR_M01"].Rows[0]["DestinationRoutingNumber"]);
To pad the filename to 30 characters, with the spaces at the start:
sbOAKAccp.Append("{0,30}", strFileName);