c# - Formatting text table in file, merging two lines per row into one -
i'm trying write information text file second row making spaces between lines
the code :
private void createdriverslist() { streamwriter w = new streamwriter(contentdirectory + "\\" + "drivers.txt"); w.writeline("module name display name driver type link date"); w.writeline("============ ====================== ============= ======================"); //declare, search, , properties in win32_systemdriver system.management.selectquery query = new system.management.selectquery("win32_systemdriver"); system.management.managementobjectsearcher searcher = new system.management.managementobjectsearcher(query); foreach (system.management.managementobject manageobject in searcher.get()) { w.writeline(manageobject["name"].tostring()); w.writeline(" " + manageobject["displayname"].tostring()); } w.close(); }
once added line :
w.writeline(" " + manageobject["displayname"].tostring());
the result in text file :
module name display name driver type link date ============ ====================== ============= ====================== 1394ohci 1394 ohci compliant host controller 3ware 3ware acpi microsoft acpi driver acpiex microsoft acpiex driver acpipagr
before added line text file :
module name display name driver type link date ============ ====================== ============= ====================== 1394ohci 3ware acpi acpiex acpipagr acpipmi
i wanted add display name row added spaces row start under display name adding spaces in between lines.
how can solve ?
**
in end text file should :
module name display name driver type link date ============ ====================== ============= ====================== 1394ohci 1394 ohci compliant ho kernel 7/26/2012 5:26:46 3ware 3ware kernel 3/8/2012 10:33:45 pm acpi microsoft acpi driver kernel 9/20/2012 9:09:16 acpiex microsoft acpiex drive kernel 7/26/2012 5:25:57 acpipagr acpi processor aggrega kernel 7/26/2012 5:27:16 acpipmi acpi power meter drive kernel 7/26/2012 5:27:33 acpitime acpi wake alarm driver kernel 7/26/2012 5:27:37
and in display name row , maybe in moudle name row make sure names in 1 line full names.
for example in display name : 1394 ohci compliant ho should : 1394 ohci compliant host controller
**
module name display name driver type link date ============ ====================== ============= ====================== 1394ohci 1394 ohci compliant host controller 3ware 3ware acpi microsoft acpi driver acpiex microsoft acpiex driver acpipagr acpi processor aggregator driver acpipmi acpi power meter driver
you've called writeline
twice in loop - it's adding 2 lines each item. want add one line, e.g.
w.writeline("{0} {1}", manageobject["name"], manageobject["displayname"]);
that won't pad spaces though, need include alignment aspect in composite format string. want left padding, need negative alignment, , looks want 12 characters before space, so:
w.writeline("{0,-12} {1}", manageobject["name"], manageobject["displayname"]);
Comments
Post a Comment