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

推荐订阅源

V
V2EX
量子位
博客园 - 司徒正美
IT之家
IT之家
V
Visual Studio Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
Microsoft Security Blog
Microsoft Security Blog
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
Vercel News
Vercel News
B
Blog
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
小众软件
小众软件
罗磊的独立博客
博客园 - 叶小钗
雷峰网
雷峰网
Martin Fowler
Martin Fowler
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学

博客园 - 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