检查行尾 [英] check for end of line

查看:66
本文介绍了检查行尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用streamreader.readline通过

行从文件行读取数据,但我需要能够检查每行的结尾,怎么可以

我用streamreader.readline完成了这个或者有更好的

方式吗?


我的代码到目前为止:


reader1 = File.OpenText(Application.StartupPath&" \ filename")

虽然不是reader1.EndOfStream

fileContents = reader1.ReadLine

output = fileContents.Split(",")

当<条件检查行结束>

------ ------------------------

------------------ ------------

结束时

cnt = cnt + 1

结束时

reader1.Close()

解决方案

因为您一次获取一行文件并将其拆分为

数组只是检查循环中数组的位置。如果您在数组的末尾获得
,那么您已经到了最后一行

-

-iwdu15

" spowel4" < sp ***** @ gmail.com写信息

新闻:11 ********************** @ 57g2000hsv。 googlegro ups.com ...


>我使用streamreader.readline通过

行从文件行读取数据但是我需要能够检查每一行的结尾,怎样才能使用streamreader.readline实现这个目标?还是有更好的

方式?


我的代码到目前为止:


reader1 = File.OpenText(Application.StartupPath&" \ filename")

而不是reader1.EndOfStream

fileContents = reader1.ReadLine

output = fileContents.Split(",")

While<检查行尾的条件>

------------------------------

------------------------------

结束时

cnt = cnt + 1

结束时

reader1.Close()



这是我在项目中使用的一段代码可能会有所帮助。


Dim fname As String = Application.StartupPath&

" \ DataFiles\RawChanData\Channel" &安培; s& " .txt"

Dim line As String ="",a()As String

如果File.Exists(fname)那么

Static LastLine()

使用sr As StreamReader = New StreamReader(fname)

Do

line = sr.ReadLine()

如果Not line = Nothing那么

a =拆分(行,〜)

流程(行,LastLine,a)

LastLine = a

结束如果

循环直到行什么都没有

sr.Close()

LastLine = Nothing

结束使用

否则

MsgBox(频道列表& fname&"未找到! ")

结束如果


-

问候,

Les Hay,Livingston,苏格兰


>如果您的


> ;数组的结尾,你到达了行的结尾



:-)


否然后 你在文件末尾


" iwdu15" < jmmgoalsteratyahoodotcomschreef在bericht

新闻:E8 ********************************** @microsof t.com ...


好​​,因为你一次获得一行文件并将其分成

一个

数组只是检查循环中数组的位置。如果你的

在阵列的末尾,你已经到了最后一行

-

-iwdu15



I am using streamreader.readline to read in data from a file line by
line but I need to be able to check for the end of each line, how can
I accomplish that using streamreader.readline or is there a better
way?

My code thus far:

reader1 = File.OpenText(Application.StartupPath & "\filename")
While Not reader1.EndOfStream
fileContents = reader1.ReadLine
output = fileContents.Split(",")
While <condition to check for end of line>
------------------------------
------------------------------
End While
cnt = cnt + 1
End While
reader1.Close()

解决方案

well since your getting the file one line at a time and splitting it into an
array just check to see where you are in the array in the loop. if your at
the end of the array, youve reached the end of the line
--
-iwdu15


"spowel4" <sp*****@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...

>I am using streamreader.readline to read in data from a file line by
line but I need to be able to check for the end of each line, how can
I accomplish that using streamreader.readline or is there a better
way?

My code thus far:

reader1 = File.OpenText(Application.StartupPath & "\filename")
While Not reader1.EndOfStream
fileContents = reader1.ReadLine
output = fileContents.Split(",")
While <condition to check for end of line>
------------------------------
------------------------------
End While
cnt = cnt + 1
End While
reader1.Close()

Here is a piece of code I use in a project that may help.

Dim fname As String = Application.StartupPath &
"\DataFiles\RawChanData\Channel" & s & ".txt"
Dim line As String = "", a() As String
If File.Exists(fname) Then
Static LastLine()
Using sr As StreamReader = New StreamReader(fname)
Do
line = sr.ReadLine()
If Not line = Nothing Then
a = Split(line, "~")
Process(line, LastLine, a)
LastLine = a
End If
Loop Until line Is Nothing
sr.Close()
LastLine = Nothing
End Using
Else
MsgBox("Channel List " & fname & " not found!")
End If

--
regards,
Les Hay, Livingston, Scotland


>if your at

>the end of the array, youve reached the end of the line

:-)

No then you are on the end of the file

"iwdu15" <jmmgoalsteratyahoodotcomschreef in bericht
news:E8**********************************@microsof t.com...

well since your getting the file one line at a time and splitting it into
an
array just check to see where you are in the array in the loop. if your
at
the end of the array, youve reached the end of the line
--
-iwdu15



这篇关于检查行尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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