c# - Row-like string with even spacing in between values -
i'm trying add multiple lines , different sections listbox, , required use "\t" creating layout.
listbox.items.add(emp[index].first + "\t\t" + emp[index].last + "\t\t" + emp[index].number + "\t\t" + emp[index].department + "\t\t" + "annual salary: " + (emp[index].annualsalary).tostring("c") + ", annual bonus: " + (emp[index].annualbonus).tostring("c"));
just 1 example line.
it comes out looking like: (without dots)
mary.......sue................778-435-2321.....accounting.....annual salary: $33,000.00 trevor....joseph...........604-894-2902.....marketing.......annual salary: $52,000.00 steve......collin.............778-234-5432.....finance..........annual salary: $48,500.00 george...........watson..........604-910-2349.....technical.......annual salary: $25,000.00 sally.......henderson.....604-654-2325.....sales..............annual salary: $12,000.00 jenny.....motgomery.....604-692-4932.....data ana.......annual salary: $12,000.00
can explain why it's displaying wonky, , how might fix this? i've searched online, couldn't find results using \t layout.
first thing, highly suggest using pattern instead of concatenating strings using plus sign. see things more clear:
string pattern = string.format("{0}\t\t{1}\t\t{2}\t\t{3}\t\tannualsalary: {4}, annual bonus: {5}", emp[index].first, emp[index].last, emp[index].number, emp[index].department, emp[index].annualsalary).tostring("c"), emp[index].annualbonus);
the answer question using tabs assuming fill space you, won't. need use advanced features of
string.format or string.pad
full answer can found here: formatting c# string identical spacing in between values
Comments
Post a Comment