在VB中 - 文件读取 [英] In VB - file reading

查看:76
本文介绍了在VB中 - 文件读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何回到上一行。例如,目前我正在阅读下面的line5:,agian我想从第2行:开始阅读。我有一个问题,比如如何回到第2行。



第1行:---做点什么----

第2行:---做点什么----

第3行:---做点什么----

第4行:---要做东西----

第5行:---做点什么----

第6行:---做点什么----
第7行:---做某事----

Hi
How to go back to previous line. For example currently i am reading the "line5:" in below case, agian i want to start the reading from "Line 2:". I have a question like how to go back to line 2.

Line 1: --- To do something----
Line 2: --- To do something----
Line 3: --- To do something----
Line 4: --- To do something----
Line 5: --- To do something----
Line 6: --- To do something----
Line 7: --- To do something----

推荐答案

如果要读取的文件不是超大文件并且是分隔的通过CRLF,您可以使用 ReadAllText 方法将整个文件读入字符串,并使用 Strings.Split 创建一个String类型的数组,其中数组的每个元素都是文件的一行。

If the files that will be read are not extra large files and are delimited by CRLF, you can use the ReadAllText method to read the entire file into a string and Strings.Split to create an array of Type String where each element of the array is a row of the file.
Dim arrFileContents() As String = Strings.Split( _
     My.Computer.FileSystem.ReadAllText( _
     "C:\bat\RestoreSQL.log"), vbCrLf)




Dim intMaxIndex as Integer = arrFileContents.GetUpperBound(0) '' The highest index of the array
Dim intFileRows as Integer = arrFileContents.GetUpperBound(0) + 1 '' The number of rows in the file


这篇关于在VB中 - 文件读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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