Archive: Cut a substring from a string by start and end strings


Cut a substring from a string by start and end strings
I need a function which do the following job:

1. Searches for a substring in string
2. If the search is OK, deletes all symbols starting from position found in '1' till the second substring given.

Example. I have an xml-file:
<root-tag>
<some-tag1>
</some-tag1>
<!--comment-->
<some-tag1/>
</root-tag>

I want to delete all from "<!--comment-->" till "/>".

Will be obliged for your advices how to do that.


Hello Yurik,

I hope this helps. Check out Afrow UKs page at the archives. It's filled with gems. http://nsis.sourceforge.net/archive/....php?userid=87

On the page are two functions which should probably help you get started.

http://nsis.sourceforge.net/archive/...php?pageid=382
http://nsis.sourceforge.net/archive/...php?pageid=383

Good luck!


Thanks alot!
This will definitely help.


Name "Output"
OutFile "Output.exe"

!include "TextFunc.nsh"
!insertmacro LineFind
!insertmacro TrimNewLines

Section
${LineFind} "C:\input.txt" "C:\output.txt" "1:-1" "LineFindCallback"

IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd

Function LineFindCallback
${TrimNewLines} '$R9' $R9

StrCmp $R0 start finish
StrCmp $R9 '<!--comment-->' 0 end
StrCpy $R0 start
goto skip

finish:
StrCpy $1 $R9 '' -2
StrCmp $1 '/>' 0 skip
StrCpy $R0 finish

skip:
StrCpy $0 SkipWrite

end:
StrCpy $R9 '$R9$\r$\n'

Push $0
FunctionEnd

Script use header

Cool, thanks!


This script for your example. If you have other lines, then that is required more code. Lines like this:
<!--comment--><some-tag2><some-tag2/>