VB.Net逐行循环查找和替换来自Datagridview的文件名

时间:2014-10-30 21:24:27

标签: vb.net replace datagridview line

我之前得到了一个名字史蒂文这个代码的帮助,但是我已经遇到了另一个绊脚石,我一直搞乱我的循环。 我有一些代码循环超过100个查找和替换,我已经添加了循环通过一些 文件查找和替换所述文件中的项目,我使用了ReadLine和WriteLine,否则我有内存问题,它就会爆炸。

使用下面的代码,我可以让它循环通过而不是查找和替换或查找和替换其中一个文件而不是循环 通过其余的文件。我在哪里出错了,我疯了。非常感谢,VBvirg


'循环播放的文件

For Each row2 As DataGridViewRow In DataGridView2.Rows
    If Not row2.IsNewRow Then
        Dim DateFile As String = row2.Cells(1).Value.ToString
        Dim DateFileConv As String = row2.Cells(2).Value.ToString
        Dim fName As String = DateFile
        Dim wrtFile As String = DateFileConv
        Dim strRead As New System.IO.StreamReader(fName)
        Dim strWrite As New System.IO.StreamWriter(wrtFile)


        While True
    'Thesre are the find and replaces
            Dim line As String = strRead.ReadLine()
            If line IsNot Nothing Then
                For Each row As DataGridViewRow In DataGridView1.Rows
                    If Not row.IsNewRow Then
                        Dim Find1 As String = row.Cells(0).Value.ToString
                        Dim Replace1 As String = row.Cells(1).Value.ToString
                        line = line.Replace(Find1, Replace1)

                    End If

                Next
                strWrite.WriteLine(line)

            End If
        End While


    End If
Next

Cursor.Current = Cursors.Default
MessageBox.Show("Finished Replacing")

0 个答案:

没有答案