c# - String builder with fixed length of characters and spaces in right side in C' -
i need string builder helps following scenarion, want create dta document that,
var name = getname() ---// name database ex- "abc gmbh" stringbuilder _header = new stringbuilder(); _header.append(string.format("{0,4}", "0128")); _header.append(string.format("{0,20}", name ));
output "0128------------abc gmbh"
but need output "0128abc gmbh-----------"
note - "-" refering empty space. need rest of spaces right side, not left side
you can use padleft
, padright
instead of string.format
:
_header.append("128".padleft(4, '0')); _header.append("abc gmbh".padright(20, ' '));
output: "0128abc gmbh "
Comments
Post a Comment