Readfile Question

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
wantedman
Newbie
Posts: 7
Joined: Tue Nov 30, 2004 1:16 pm

Readfile Question

Post by wantedman » Tue Apr 19, 2005 4:51 pm

Trying to use readfile to Replace some text in a file. I know how to do it with the ReadLN function but its so extremely slow I just can't use it. I need to be able to read a file and if a certain text is in the file then do something. but the text I need to find is on three lines.
Example

TYPEID_GAMEOBJECT_BETA3_WM
GAMEOBJECT_FACING
TYPEID_GAMEOBJECT_BETA3_WM

that is the text I need to find and replace it with

TYPEID_GAMEOBJECT_BETA3_WM

is there ANY function that will read a file and have the ability to read each line of the file instead of one long string?

Also what is the characters between the two lines? is it a CR?

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Apr 19, 2005 5:20 pm

Between each lines will be a carriage return and linefeed -CRLF.

So you might just be able to do this:

Let>needle=TYPEID_GAMEOBJECT_BETA3_WM%CRLF%GAMEOBJECT_FACING%CRLF%TYPEID_GAMEOBJECT_BETA3_WM
Let>replacement=TYPEID_GAMEOBJECT_BETA3_WM
ReadFile>filename,buffer
StringReplace>buffer,needle,replacement,buffer

Then write out the buffer to a new file with WriteLn (and delete and replace old file with new file if required).
MJT Net Support
[email protected]

wantedman
Newbie
Posts: 7
Joined: Tue Nov 30, 2004 1:16 pm

wow

Post by wantedman » Tue Apr 19, 2005 6:34 pm

that worked awesome! VERY fast doing it this way.. readln way took about 1 min where this was seconds.!!!! thanks alot. May want to put this in your help file as a sample!

WM

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts