Prev Previous Post   Next Post Next
Old 26th July 2018, 23:09   #1
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Red face loop issue

Hi everyone
im having a small loop issue i need little help with,
i am trying to search in file first to find a specific entry; followed by another search and replace,

my start test.txt file looks like this
PHP Code:
mod={1234}
size=11

mod
={1235}
size=11 

i am trying to search for "mod={1234}" than replace the "size=*" that follows,
as a starting point the number after "size=" can be any number,
i am searching for the next line start and replacing the entire line after the first match is found,
it seem to work accept its looping on me; it keeps finding "size=" and replacing it throughout the file,

i am trying to get to this
PHP Code:
mod={1234}
size=22

mod
={1235}
size=11 
but i keep ending up with this
PHP Code:
mod={1234}
size=22

mod
={1235}
size=22 
why is it looping instead of replacing just the first match?
this is the code i am currently using,

PHP Code:
!include "TextFunc.nsh"
!insertmacro LineFind

!define FIND1 "mod={1234}"
!define FINDNEXT "size="
!define REPL1 "size=22"

outFile "test.exe"

Function LineFindCallback
        StrLen 
$"${FIND1}"
        
StrLen $"${FINDNEXT}"
        
StrCpy $"$R9$0
        StrCmp 
$"${FINDNEXT}0 End
        StrCpy $R9 
"${REPL1}$\r$\n"

        
End:
        
Push $0
FunctionEnd

Section Install
        
${LineFind"test.txt" "test.txt" "1:-1" "LineFindCallback"

        
IfErrors 0 +2
        MessageBox MB_OK 
"Error"
SectionEnd 

TIA
Chris
MyPC8MyBrain is offline   Reply With Quote
 
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump