阅读和解析文本文件的第1行7行 [英] Read & parse 1st 7 lines of text file

查看:58
本文介绍了阅读和解析文本文件的第1行7行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要您的指导才能完成我正在进行的一个小项目.

基本上,我需要使用VB.NET打开一个文本文件.读取文件中的第1 7行,同时将每一行拆分为数组,并为每个段分配一个变量.之后,我将需要替换某些变量并写回文本文件.

这是我在下面尝试过的代码:

I need your guidance to complete a small project I am working on.

Basically, I need to use VB.NET to open a text file; read the 1st 7 lines in the file while splitting each line into arrays and assign a variable to each segment. After, I will need to replace certain variables and write back to text file.

This is the code I have attempted below:

Private Sub btnFixation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFixation.Click
        'read file line by line; parse lines
        Dim myLine As String = ""
        Dim LineOfPeas As String
        Dim t As Integer
        Dim aryPeasLine(6) As String
        Dim objReader As New System.IO.StreamReader(Me.lblPeasFile.Text)

        Do While objreader.peek() <> -1
            PeasLine = PeasLine & objReader.ReadLine() & vbNewLine

        Loop

        LineOfPeas = myLine
        aryPeasLine = LineOfPeas.Split("*")
        LineOfPeas = LineOfPeas.Replace("STUBBS", "FUGEES")
        For t = 0 To 6

        Next t
        MessageBox.Show(LineOfPeas)
    End Sub


tia


tia

推荐答案

我注意到的第一件事是,您将"myLine"声明为空字符串,但随后从未为其分配值.在执行期间为"PeasLine"分配了值,但随后不再使用"PeasLine".然后,将空的"myLine"分配给LineOfPeas.根据拆分情况,找不到数组,因此结果是...不是您想要的.

希望这将使您走上解决方案的道路.最好的祝福!杰伊
The first thing I noticed was that you declare "myLine" as an empty string, but then you never assign a value to it. "PeasLine" is assigned values inside the do-while, but then "PeasLine" is never used again. You then assign the empty ''myLine'' to LineOfPeas. The array has nothing to find based on your split, so the result is... not what you wanted.

Hopefully that will get you on the path to a solution. Best Regards! Jay


这篇关于阅读和解析文本文件的第1行7行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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