[Closed] Finding and Replacing text in a text file
hey guys,
I recently discovered, on this forum, a way to have multiple floaters using the same script without creating a conflict. It basically has a rollout in a text file, and the script replaces the name, title, and other data in the text file with an unique string, then runs the it.
On Console pressed do
(
local FSin = Openfile ((GetDir(#scripts))+"\\SyRGB\\Data\\CapConsole.ms") mode:"r"
local FSOut = Openfile ((GetDir(#scripts))+"\\SyRGB\\Data\\CapConsoleTemp.ms") mode:"w"
local tnRollName = ""
local tnLine
do
(
tnLine = readLine FSin
if
(
matchpattern tnLine pattern:"*rollout_*"
)
then
(
if
(
tnRollName == ""
)
then
(
Local RollExists = false
local RollCount = 0
tnRollName = (filterString tnLine " ")[2]
do
(
RollCount += 1
RollExists = execute ( "( Classof " + tnRollName + ( RollCount as string ) + " == RolloutClass )" )
if
(
RollExists
)
then
(
local Rollopen = execute ( tnRollName + ( RollCount as string ) + ".open" )
if
(
not Rollopen
)
then
(
execute ( tnRollName + ( RollCount as string ) + "=undefined" )
RollExists = false
)
)
)
while
(
RollExists
)
)
tnLine2 = replace tnLine ( findString tnLine "rollout_" ) 8 ("rollout_"+ ( RollCount as string ))
)
format "%
" tnLine to:FSOut
)
while
(
not eof FSin
)
close FSin
close FSOut
filein ((GetDir(#scripts))+"\\SyRGB\\Data\\CapConsoleTemp.ms")
deleteFile ((GetDir(#scripts))+"\\SyRGB\\Data\\CapConsoleTemp.ms")
)
I’ll be honest, I don’t really understand what its doing, but its working.
The problem is I want to throw a wrench into the works by replacing another string in the original text file with a predetermined variable. I’m not sure how to make max find the string in the original file that i want to replace. Nor am I sure where in the script such an action would belong. The string that I need to replace occurs only once. FindString isn’t working.
any ideas guys?
Do you have an example of what your code is doing and where??
I’d imagine it work as a “else” branch to the main if statement (looking for “rollout”)
Shane
FindString only works with a String, not a StringStream or FileStream. You probably want to use SkipToString, or cast as a string and use findString.