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

I have found when using the replace function in vb you need to assign it to a different var
Example:
tempstr = str.replace(string1,string2)
str=string.empty
str=tempstr.replace(string2,string3)

Hi thanks for your reply and yes you are right i tried your idea and it works, for some reason
there is a buffer underun when reading large .txt files in excess of 1 gig this is on a soltry main frame which is a clustered IBM z990 implemented by my team and i. All is well many thanks.

Domino.VBcoder

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.