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

查看:182
本文介绍了C#如何将Console.Writeline输出保存为HTML格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从日志文本文件中取出字符串后输出各种结果的程序。结果显示在命令行控制台上。



因此,有没有办法将各种输出结果生成为基于HTML的报告?



有什么方法可以用于转换输出? HtmlTextWriter的?转换文件需要什么步骤?



可能有人请告诉我们这些代码吗?

代码:

  using System; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Diagnostics;
使用System.IO;
使用System.Text.RegularExpressions;
使用System.Web.UI; //系统告诉我它不存在于命名空间System.web中。


foreach(lines.Skip(1)中的字符串r)
{
String [] token = r.Split(',');

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

String timeText = datetime [4];

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

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

字符串操作=标记[2];

String fileName = token [7]; ((Path.GetExtension(token [7])。Contains(。exe)||(Path.GetExtension(token [7])。Contains(。msi))) )
{

Console.WriteLine(这个数组的时间是:+ timeText);

Console.WriteLine(token [7]);

Console.WriteLine(actions);

Console.WriteLine(fileSize);

ProgramFilter(actions,k,fileName);

x = 1;

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

$ b

}

解决方案

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

只需将文本转换为HTML格式即可 - 您需要决定标记的内容。



有很多选项可以做到这一点:




  • 使用ASP.NET作为模板并阅读结果

  • 使用StringBuilder构建HTML

  • 使用HtmlTextWriter构建HTML

  • 将数据转换为XML并使用XSLT进行转换






至于写入文件 - 再次,有几种方法可以做到这一点:


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:

这篇关于C#如何将Console.Writeline输出保存为HTML格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆