Search a string in text file and edit

Hello,
I need to read a text file to locate a certain string and if matches then replace the line with new string. I can read the line and check whether it matches or not but cant find anything how to replace or edit current line.

How does your code look like? Check out replace (http://documentation.xojo.com/api/deprecated/replace.html) for replacing text.

@Beatrix Willius here is how the code looks. the replace works within xojo app but i have to write back to the text file.

While Not MyInputStream.EOF Dim line As String = MyInputStream.ReadLine If InStr(line, "Desired String") > 0 Then ' match found 'here i need to replace the matched string 'write the new string replacing the old one to the text file and close End If Wend

If your file is very small (only a couple of lines) then use ReadLine. Otherwise, use a TextInputStream or a BinaryStream.

Read your data into a string array:

[code]dim myText(-1) as string

While Not MyInputStream.EOF
Dim line As String = MyInputStream.ReadLine
If InStr(line, “Desired String”) > 0 Then
’ match found
'here i need to replace the matched string
'write the new string replacing the old one to the text file and close
line = replace(line, “Desired String”, “something else”
myText.append(line) '<—
End If
Wend

dim newText as string = join(myText, endOfline)
'now you can write your result into a new text file or replace the old one[/code]

Thanks @Beatrix Willius .