欢迎来到飞鸟慕鱼博客,开始您的技术之旅!
当前位置: 首页知识笔记正文

Title: Reading unix-style Text with VB.NET file

墨初 知识笔记 90阅读

Unix操作系统文本换行仅用于指示行尾net streamreader的阅读线函数不适用于unix操作系统文本文件。我为StreamReader类制作了一个小包装器,以便它可以处理unix操作系统格式。起初,我创建了一个类代码导入系统iopublicclasstreamreaderunixinheritstreamreadersubnew(ByVal;我的基地new()EndSubPublicFunctionReadLine(ByValunixStyleAs 255,1)' String dimintbyteasintegerdimbteread()AsByteDimmybuffer(1)aschardimlinefeedlocationasintegerdimlineas

, 1)">String/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">=/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">String/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">.Empty /span>/span>/span>/span>/span>/span>/span>/span>br>        /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">If/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> unixStyle /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">=/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 0, 1)">""/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Then/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br>            /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)"/span>/span>/span>/span>/span>/span>/span>/span>span class="xzm_is" data-txt="MyBase#3C"/span>/span>/span>/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">.ReadLine()
        /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Else/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>br>            /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Do/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">While/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Not/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> intByte /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">=/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">-/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 128, 1)">1/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br>                intByte /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">=/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)"/span>/span>/span>/span>/span>/span>/span>/span>span class="xzm_is" data-txt="MyBase#3C"/span>/span>/span>/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">.Read(mybuffer, /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 128, 1)">0/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">, /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 128, 1)">1/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">)
                /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">If/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> intByte /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"><>/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">-/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 128, 1)">1/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Then/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br>                    lineFeedLocation /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">=/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> Array.IndexOf(mybuffer, /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)"/span>/span>/span>/span>/span>/span>/span>/span>span class="xzm_is" data-txt="CChar#3C"/span>/span>/span>/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">(vbLf))
                    /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">If/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> mybuffer(/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 128, 1)">0/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">) /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">=/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)"/span>/span>/span>/span>/span>/span>/span>/span>span class="xzm_is" data-txt="CChar#3C"/span>/span>/span>/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">(vbLf) /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Then/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br>                        /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Return/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> aLine
                    /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">ElseIf/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> mybuffer(/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 128, 1)">0/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">) /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">=/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)"/span>/span>/span>/span>/span>/span>/span>/span>span class="xzm_is" data-txt="CChar#3C"/span>/span>/span>/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">(vbCr) /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Then/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br>                        /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 128, 0, 1)">'/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 128, 0, 1)">doing nothing/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 128, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br/span>/span>/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">                    /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Else/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br>                        aLine /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">=/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> aLine /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">&/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> mybuffer(/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 128, 1)">0/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">)
                    /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">End/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">If/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br>                /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">End/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">If/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br>            /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Loop/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br>        /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">End/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">If/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>br>    /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">End Function/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br/span>/span>/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">End Class/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br/span>/span>/span>/span>/span>/span>/span>/span>/span> /span>/span>/span>/span>/span>/span>/p> /span>/span>/span>/span>/span>/span>/p>

Below is the sample code to use this class

/span>/span>/span>/span>/span>/span>/p>
/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Dim/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> oRead /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">As/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span/span>/span>/span>/span>br>oRead /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">=/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)"/span>/span>/span>/span>span class="xzm_is" data-txt="New#3C"/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>(/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 0, 1)">"/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 0, 1)">sample.txt/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 0, 1)">"/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">)/span>/span>/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">Dim/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> lineIn /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">As/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">String/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br/span>/span>/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">While/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> oRead.Peek /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"><>/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">-/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 128, 1)">1/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span>/span>br>   lineIn /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">=/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"> oRead.ReadLine(/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 0, 1)">"/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 0, 1)">unix/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(128, 0, 0, 1)">"/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">)
   /span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)"/span>/span>span class="xzm_is" data-txt="MsgBox#3C"/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)">(lineIn)/span>/span>/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">End/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 0, 1)"/span>/span>/span>/span>/span>/span>/span/span>/span>/span>/span>/span>/span>/span>/span>span style="color: rgba(0, 0, 255, 1)">While/span>/span>/span>/span>/span>/span>/span>/span>/div/span>/span>/span>/span>/span>/span>/span>/span>/div> /span>/span>/span>/span>/span>/span>/p> /span>/span>/span>/span>/span>/span>/p>
/span>/span>/span>/span>/span>/span>/span>/span>/div>

标签:
声明:无特别说明,转载请标明本文来源!