Really WEIRD Strings n Things

Joined
Oct 2, 2007
Messages
14
Programming Experience
1-3
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

VB.NET:
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
 
Last edited by a moderator:
Correct code for replacing part of a string

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oldstr, newstr, delstr, repstr As String
        oldstr = "NUCLEAR=\ssmsilo191\secure access\hal9000"
        delstr = "ssmsilo191\secure access\hal9000"
        repstr = "sdrsillo252\access secure trunk119\sepi2100"
        newstr = oldstr.Replace(delstr, repstr)
        MessageBox.Show(newstr)
    End Sub
 
Last edited by a moderator:
Update

Thanks for the reply i have fixed the issue it seemed to be a buffer under-run error which is quite shocking because its a 1 gig .txt file on a clustered IBM z990 ??? so this raises questions on a scale you wouldnt believe even if i told you.

Many Thanks

Domino.VBcoder
 
Back
Top