You are here: PSPad forum > English discussion forum > increment in replace
Posted by: icek | Date: 05/09/2011 10:33 | IP: IP Logged
Hello,
I'm a new user of PSPad and I don't know how to make scripts.
In an XML file I'd like to search the following tags :
<sequence>50</sequence>
<sequence>60</sequence>
<sequence>65</sequence>
...
<sequence>n</sequence>
and rewrite properly the increment
<sequence>1</sequence>
<sequence>2</sequence>
<sequence>3</sequence>
...
<sequence>n</sequence>
I guess that I have to use search/replace but I don't know the syntax.
May someone help me please?
Thanks in advance.
David
Posted by: vbr | Date: 05/09/2011 13:03 | IP: IP Logged
icek:Hello,I'm a new user of PSPad and I don't know how to make scripts.
In an XML file I'd like to search the following tags :
<sequence>50</sequence>
<sequence>60</sequence>
<sequence>65</sequence>
...
<sequence>n</sequence>and rewrite properly the increment
<sequence>1</sequence>
<sequence>2</sequence>
<sequence>3</sequence>
...
<sequence>n</sequence>I guess that I have to use search/replace but I don't know the syntax.
May someone help me please?
Thanks in advance.
David
Hi,
as far a I know, this is not available in the builtin replace functionality.
You can use my rather hackish script addon
www.vbr.wz.cz
Be sure to make a backup of the source data, especially on larger files and with invalid input the mentioned javascript can cause problems. (Some caveats are on the homepage too.)
The pattern for replace would be e.g.:
Quote:/(<sequence>)(\d+)(<\/sequence>)/gi, function(match, paren1, paren2, paren3){globParamArr[0]=0; globParamArr[globParamArr.length] = globParamArr[globParamArr.length-1] +1; return paren1+globParamArr[globParamArr.length-1]+paren3;}
To reset the counter you have to use "recompile scripts" in the Scripts menu (the pattern will be cleared too.)
Or you can use the *eval* item in the script menu with the following:
Quote:globParamArr = new Array();
hth,
vbr
Edited 1 time(s). Last edit at 05/09/2011 13:16 by vbr.
Posted by: icek | Date: 05/12/2011 12:14 | IP: IP Logged
Thanks a lot my friend... but it dosn't work.
PSPad bugs when I use multiple search&replace, it closes by itself.
Never mind, thanks again for your kind help,
David
Editor PSPad - freeware editor, © 2001 - 2013 Jan Fiala
Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák