How to replace single line in text withot saving the file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Marko Danilovic
    New Member
    • Dec 2010
    • 11

    How to replace single line in text withot saving the file?

    I need to open some HTML file, then replace exact line of text with another, and then WITHOUT SAVING THE FILE (WriteAllLines( HTML01, lines)) to display in WebBrowser. My code in private sub of replacing the line is next:

    Code:
            Dim lines() As String = System.IO.File.ReadAllLines(HTML01)
            lines(7) = "editovan HTML"
            WriteAllLines(HTML01, lines)   'without this line, just in RAM memory
            WebBrowser1.DocumentText = System.IO.File.ReadAllText(HTML01)
    The file "HTML01" as already opened.

    Thanks in advance!
  • Marko Danilovic
    New Member
    • Dec 2010
    • 11

    #2
    In the meantime I resolve the question by myself:

    Code:
    Imports System.IO.File
    Imports System.IO
    Imports System.Text
    
    Public Class Form1
    
        Dim HTML01 As String = (CurDir() & "\10.html")
        Dim HTML02 As String
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            WebBrowser1.DocumentText = System.IO.File.ReadAllText(HTML01)
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim lines() As String = System.IO.File.ReadAllLines(HTML01)
            lines(7) = "edited HTML"
    
            Dim HTML02 As String = ""
            For i = 0 To 8 ' lines in HTML01 is 9
                If i = 8 Then
                    HTML02 = HTML02 & lines(i)
                Else
                    HTML02 = HTML02 & lines(i) & Chr(13) & Chr(10)
                End If
                'MsgBox("linija:" & i & " = " & lines(i))
            Next i
    
            'System.IO.File.WriteAllText(putanja, HTML02) - this line is no need it
            WebBrowser1.DocumentText = HTML02
            
        End Sub
    End Class

    Comment

    Working...