Vb.net Net从Datagridview逐行查找和替换文件名

Vb.net Net从Datagridview逐行查找和替换文件名,vb.net,replace,datagridview,line,Vb.net,Replace,Datagridview,Line,我之前得到了一个叫史蒂文的家伙的善意帮助,但是我遇到了另一个绊脚石,我一直把我的循环弄得一团糟。 我有一些代码可以循环使用超过100k的查找和替换,我在其中添加了循环使用大量 要查找和替换上述文件中的项目,我使用了ReadLine和WriteLine,否则我会出现内存问题,它会爆炸 有了下面的代码,我可以让它循环使用而不查找并替换,或者查找并替换其中一个文件而不循环 通过其余的文件。我的循环哪里出了问题,我快疯了。非常感谢,维格 '要循环浏览的文件 For Each row2 As DataGr

我之前得到了一个叫史蒂文的家伙的善意帮助,但是我遇到了另一个绊脚石,我一直把我的循环弄得一团糟。 我有一些代码可以循环使用超过100k的查找和替换,我在其中添加了循环使用大量 要查找和替换上述文件中的项目,我使用了ReadLine和WriteLine,否则我会出现内存问题,它会爆炸

有了下面的代码,我可以让它循环使用而不查找并替换,或者查找并替换其中一个文件而不循环 通过其余的文件。我的循环哪里出了问题,我快疯了。非常感谢,维格

'要循环浏览的文件

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")

你看到了吗?好吧,那永远不会存在,也就是说,永远不会离开循环。我想那不是你想要的。此外,您必须在streamreader/Writer上使用.Dispose;你可以使用一个构造来处理这个问题。嗨,安德鲁,但是如果我移动while循环,它会创建所有文件,而不是一行一行地查找和替换一个文件,然后移动到下一个文件。I m in Loop hell.While True应该是While而不是stread.EndOfStream,这样循环可以在到达输入文件结尾时完成。您在代码顶端时放弃了出口,Andrew先生,非常感谢您,我现在可以在断开的循环中睡觉而不做梦了:再次感谢您。如果我知道你在哪里,我会给你买一品脱的。