惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
月光博客
月光博客
博客园 - 司徒正美
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
量子位
Recent Announcements
Recent Announcements
V
V2EX
P
Proofpoint News Feed
小众软件
小众软件
云风的 BLOG
云风的 BLOG
腾讯CDC
宝玉的分享
宝玉的分享
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
B
Blog
博客园_首页
GbyAI
GbyAI
博客园 - Franky

博客园 - IT 笔记

Subversion Revert File will not be shown in Modification Surprise vb.net WinForm don't require instance to access the instance value Properties.Settings show error 'System.Windows.Forms.PropertyStore' does not contain a definition for 'Settings' Add Image in MS Report RDLC by using Embedded Image 王爽汇编 Lab 13 Question 1, 用两个程序实现 Spring.NET Installation and setup the first program 王爽汇编语言 实验11 王爽汇编语言 检测点11.2 王爽 汇编语言程序课程设计1 王爽 汇编语言程序设计实验10,题三,数值转换。(Assembly experiment Convert HEX to Decimal and Show on screen ) 王爽 汇编语言程序设计 实验9 (Assembly Language Study) 王爽 汇编语言程序设计 检测点9.1 第2题 The NTVDM CPU has encountered an illegal instruction. CS:0006 IP:130a .... select files by multiple extension name Access Denied when running Spring.IocQuickStart.MovieFinder How to install autotrace in fontforge My first postscript program .net 2 config A generic winform skeleton support interactive UI during large job process
using vb.net read unix style text file
IT 笔记 · 2010-03-22 · via 博客园 - IT 笔记

Unix text file uses linefeed only to indicate end of line, the .net streamreader's readline function is not working with unix text file.

I made a small wrapper for StreamReader class to make it is working with unix format.

At first, I created a class

代码

Imports System.IOPublic Class StreamReaderUnix
    
Inherits streamreader
    
Sub New(ByVal filename As String)
        
MyBase.New(filename)
    
End SubPublic Function ReadLine(ByVal unixStyle As StringAs String
        
Dim intByte As Integer
        
Dim bteRead() As ByteDim mybuffer(1As Char
        
Dim lineFeedLocation As Integer
        
Dim aLine As String = String.Empty If unixStyle = "" Then
            
MyBase.ReadLine()
        
Else 
            
Do While Not intByte = -1
                intByte 
= MyBase.Read(mybuffer, 01)
                
If intByte <> -1 Then
                    lineFeedLocation 
= Array.IndexOf(mybuffer, CChar(vbLf))
                    
If mybuffer(0= CChar(vbLf) Then
                        
Return aLine
                    
ElseIf mybuffer(0= CChar(vbCr) Then
                        
'doing nothing
                    Else
                        aLine 
= aLine & mybuffer(0)
                    
End If
                
End If
            
Loop
        
End If 
    
End Function
End Class

Below is the sample code to use this class

Dim oRead As StreamReaderUnix
oRead 
= New StreamReaderUnix("sample.txt")
Dim lineIn As String
While oRead.Peek <> -1
   lineIn 
= oRead.ReadLine("unix")
   
MsgBox(lineIn)
End While