Jump to content
Sign in to follow this  
Hentie

StringReplace?

Recommended Posts

Hentie

Please Help! Something that was supposed to be quite simple just turned out to be "impossible". I just can't get my head around this.

My problem: I've got a string in a text file that I want to find and replace but it seems impossible. I can't find a string in a text file without opening the file as read only and if I open the file in write mode then I can't do a FileRead and only have 2 write options:

1. Append to the end of the file

2. Overwite the entire contents of the file.

I'm obviously missing something?

This is what I've got so far:

if FileExists ($FileName) Then

$file = FileOpen($FileName, 0)

if Not($file = -1) Then

While 1

$line = FileReadLine($file)

;Msgbox (0, 'line', $line)

If @error = -1 Then ExitLoop

$s = StringInStr($line, $Customstr)

if not($s=0) Then

MSGBOX (0, "Match Found", $line)

;Now replace the string...?????

EndIf

Wend

EndIf

FileClose($file)

EndIf

Share this post


Link to post
Share on other sites
SlimShady

Functions you need:

- _FileReadToArray (see help file for info)

- FileOpen in overwrite mode

- StringReplace

- FileWriteLine

Edited by SlimShady

Share this post


Link to post
Share on other sites
automagician

I was just going to give you the solution, but you'll learn more if you do it on your own with the functions from Slim...just give a shout if you still need help....

Share this post


Link to post
Share on other sites
Hentie

:D:)

Thanks to you guys it turned out to be easy after all.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.