private voID CreateDriversList(){ StreamWriter w = new StreamWriter(contentDirectory + "\" + "Drivers.txt"); w.Writeline("Module name display name Driver Type link Date"); w.Writeline("============ ====================== ============= ======================"); //Declare,Search,and Get the 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();}@H_301_7@一旦我添加了这条线: @H_301_7@
w.Writeline(" " + ManageObject["displayname"].ToString());@H_301_7@文本文件中的结果如下: @H_301_7@
Module name display name Driver Type link Date============ ====================== ============= ======================1394ohci 1394 OHCI Compliant Host Controller3ware 3wareACPI Microsoft ACPI DriveracpIEx Microsoft ACPIEx Driveracpipagr@H_301_7@在我添加行之前,文本文件是这样的: @H_301_7@
Module name display name Driver Type link Date============ ====================== ============= ======================1394ohci3wareACPIacpIExacpipagrAcpiPmi@H_301_7@我只是想现在添加显示名称行,所以我添加了空格,因此行将在显示名称下开始,然后在行之间添加空格. @H_301_7@我怎么解决呢? @H_301_7@** @H_301_7@最后,文本文件应如下所示: @H_301_7@
Module name display name Driver Type link Date ============ ====================== ============= ======================1394ohci 1394 OHCI Compliant Ho Kernel 7/26/2012 5:26:46 AM 3ware 3ware Kernel 3/8/2012 10:33:45 PM ACPI Microsoft ACPI Driver Kernel 9/20/2012 9:09:16 AM acpIEx Microsoft ACPIEx Drive Kernel 7/26/2012 5:25:57 AM acpipagr ACPI Processor Aggrega Kernel 7/26/2012 5:27:16 AM AcpiPmi ACPI Power Meter Drive Kernel 7/26/2012 5:27:33 AM acpitime ACPI Wake Alarm Driver Kernel 7/26/2012 5:27:37 AM@H_301_7@并在显示名称行中,也可能在moudle名称行中,以确保名称将在一行全名. @H_301_7@例如,在显示名称中:1394 OHCI Compliant Ho
应该是:1394 OHCI兼容主机控制器 @H_301_7@** @H_301_7@
Module name display name Driver Type link Date============ ====================== ============= ======================1394ohci 1394 OHCI Compliant Host Controller3ware 3wareACPI Microsoft ACPI DriveracpIEx Microsoft ACPIEx Driveracpipagr ACPI Processor Aggregator DriverAcpiPmi ACPI Power Meter Driver解决方法 你已经在循环中调用了Writeline两次 – 所以它为每个项添加了两行.您只想添加一行,例如 @H_301_7@ @H_301_7@
w.Writeline("{0} {1}",ManageObject["name"],ManageObject["displayname"]);@H_301_7@这不会填充空格,所以你需要在composite format string中包含一个对齐方面.你想要左边填充,所以你需要一个负对齐,看起来你想在空格前有12个字符,所以: @H_301_7@
w.Writeline("{0,-12} {1}",ManageObject["displayname"]);总结
以上是内存溢出为你收集整理的c# – 在文件中格式化文本表,将每行合并两行全部内容,希望文章能够帮你解决c# – 在文件中格式化文本表,将每行合并两行所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)