开发者

Find and replace a text in XML using VB.net

开发者 https://www.devze.com 2023-03-15 02:01 出处:网络
I have a XML file. Inside t开发者_开发百科he XML file where ever I find the string as (\"C:\\Results\\test1_01\") I need to replace it with (\"B:\\final\\test1_01\") and save it. Please guide me for t

I have a XML file. Inside t开发者_开发百科he XML file where ever I find the string as ("C:\Results\test1_01") I need to replace it with ("B:\final\test1_01") and save it. Please guide me for this.

Thanks in advance,


       Try
            Dim fOut as StreamWriter = New StreamWriter("Output.xls")
            Using sr As StreamReader = New StreamReader("YourXMLFile.xml")
                Dim line As String
                Do
                  line = sr.ReadLine()
                fOut.WriteLine(Line.Replace("C:\Results\test1_01","B:\final\test1_01"))
                Loop Until line Is Nothing
                sr.Close()
                fOut.Close()
            End Using
        Catch E As Exception
            ' Let the user know what went wrong.
            Console.WriteLine("The file could not be read:")
            Console.WriteLine(E.Message)
        End Try
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号