' text2html.vb Imports System Imports System.IO Imports System.Web Imports System.Text Imports Microsoft.VisualBasic Public Class TextToHtml Const TabSize As Integer = 4 Shared sjisEnc As Encoding = Encoding.GetEncoding("Shift_JIS") Shared Function IsZenkaku(c As Char) As Boolean Return sjisEnc.GetByteCount(New Char() {c}) = 2 End Function Shared Function ExpandTabs(ByVal s As String) As String Dim column As Integer = 0 Dim sb As StringBuilder = New StringBuilder() Dim c As Char For Each c In s If c = ControlChars.Tab Then sb.Append(" ", TabSize - (column Mod TabSize)) column = 0 Else sb.Append(c) column += 1 If IsZenkaku(c) Then column += 1 End If Next Return sb.ToString() End Function Shared Sub Main(ByVal args() As String) Dim line As String Dim sr As StreamReader = New StreamReader(args(0),sjisEnc) line = sr.ReadLine() While Not line Is Nothing Dim html As String = HttpUtility.HtmlEncode(line) html = ExpandTabs(html) html = html.Replace(" ", " ") + "
" Console.WriteLine(html) line = sr.ReadLine() End While sr.Close() End Sub End Class ' コンパイル方法:vbc /r:System.Web.dll text2html.vb