Hi all im Domino.vbcoder
I am currently writing a security logger for a client, part of the project reads a txt file and searches for a line then replaces the line with a specified string as the code shows bellow, my problem is when it replaces the line with the specified string it some how leaves behind part of the line that was there previously. I have tested the app vigoruosly to find the problem but no luck. So to recap for example i am replaceing a line that starts with 'NUCLEAR=\ssmsilo191\secure access\hal9000' with a string that is 'NUCLEAR=\sdrsillo252\access secure trunk119\sepi2100' and im getting a resulting string of NUCLEAR=\sdrsillo252\access secure trunk119\sepi2100\hal9000, the strings that are concatenated are all as they should be. Can anyone help with another way of replaceing the string in an overhead friendly way ? plzz post code if possibble this is very important.
Many Thanks
Domino.vbcoder
Private Sub textwritetest()
Dim strstring2 As String = strpathforcurrent.ToUpper & "\" & gstrprojectname.ToUpper & "\" & gstrojobname.ToUpper
Dim str As String
Dim Fs As FileStream = New FileStream(strpathforcurrent & "\data.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim sw As New StreamWriter(Fs)
Dim sr As New StreamReader(Fs)
str = sr.ReadToEnd()
str = str.Replace("NUCLEAR=" & gstrprojectfromcurrent, "NUCLEAR=" & strpathforcurrent.ToUpper & "\" & gstrprojectname.ToUpper)
str = str.Replace("NUCLEAR=" & strforward, "NUCLEAR=" & strstring2)
Fs.Position = 0
Fs.SetLength(str.Length)
sw.Write(str)
sw.Flush()
sw.Close()
Fs.Close()
End Sub