C#如何将Console.Writeline输出保存到HTML格式?[英] C# How to save Console.Writeline Outputs to HTML Format?

本文是小编为大家收集整理的关于C#如何将Console.Writeline输出保存到HTML格式?的处理方法,想解了C#如何将Console.Writeline输出保存到HTML格式?的问题怎么解决?C#如何将Console.Writeline输出保存到HTML格式?问题的解决办法?C#如何将Console.Writeline输出保存到HTML格式?问题的解决方案?那么可以参考本文帮助大家快速定位并解决问题,译文如有不准确的地方,大家可以切到English参考源文内容。

问题描述

我有一个程序,该程序在从日志文本文件中求助于字符串后,输出各种结果.结果显示在命令行控制台上.

因此,无论如何是否有将各种输出结果生成基于HTML的报告?

可以使用哪些方法来转换输出? htmltextwriter?转换文件需要什么步骤?

有人请有人建议代码这样做吗?谢谢!

代码:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Diagnostics;
 using System.IO;
 using System.Text.RegularExpressions;
 using System.Web.UI; // The system is telling me that it does not exist in the namespace System.web....


        foreach (String r in lines.Skip(1))
        {
            String[] token = r.Split(',');

            String[] datetime = token[0].Split(' ');

            String timeText = datetime[4];

            Double rawSize = Convert.ToDouble(token[1]);

            Double fileSize = ((rawSize / 1024) / 1024);

            String actions = token[2];

            String fileName = token[7];

            if ((Path.GetExtension(token[7]).Contains(".exe") || (Path.GetExtension(token[7]).Contains(".msi"))))
            {

                Console.WriteLine("The time for this array is: " + timeText);

                Console.WriteLine(token[7]);

                Console.WriteLine(actions);

                Console.WriteLine(fileSize);

                ProgramFilter(actions, k, fileName);

                x = 1;

                Console.WriteLine("================================================");

            }

}

推荐答案

HTML是一种基于文本的格式,因此您可以简单地输出HTML.

没有什么可以为您转换为HTML的任何内容 - 您需要确定标记的内容.

有很多选择要这样做:

  • 使用ASP.NET作为模板并读取结果
  • 使用StringBuilder构建HTML
  • 使用htmltextwriter构建html
  • 将数据转换为XML,并用XSLT
  • 将其转换为

至于写入文件 - 再次,几种方法:

本文地址:https://www.itbaoku.cn/post/879631.html

问题描述

I have a program which outputs various results after greping strings from a log text file. The results are shown onto a command line console.

Therefore are there anyways to generate the various output results into a html based report?

What methods could be used to convert the outputs? HtmlTextWriter? What are the steps needed to convert the file?

May someone please advise on the codes to do so? Thanks!

The codes:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Diagnostics;
 using System.IO;
 using System.Text.RegularExpressions;
 using System.Web.UI; // The system is telling me that it does not exist in the namespace System.web....


        foreach (String r in lines.Skip(1))
        {
            String[] token = r.Split(',');

            String[] datetime = token[0].Split(' ');

            String timeText = datetime[4];

            Double rawSize = Convert.ToDouble(token[1]);

            Double fileSize = ((rawSize / 1024) / 1024);

            String actions = token[2];

            String fileName = token[7];

            if ((Path.GetExtension(token[7]).Contains(".exe") || (Path.GetExtension(token[7]).Contains(".msi"))))
            {

                Console.WriteLine("The time for this array is: " + timeText);

                Console.WriteLine(token[7]);

                Console.WriteLine(actions);

                Console.WriteLine(fileSize);

                ProgramFilter(actions, k, fileName);

                x = 1;

                Console.WriteLine("================================================");

            }

}

推荐答案

HTML is a text based format, so you can simply output HTML.

There isn't anything that will simply convert text into HTML for you - you need to decide what the markup will be.

There are many options to do this:

  • Using ASP.NET as a template and reading the result
  • Using a StringBuilder to build up your HTML
  • Use HtmlTextWriter to build up the HTML
  • Convert the data to XML and transform it with XSLT

As for writing to a file - again, several ways to do this:

查看更多