Page 1 of 1

Replacing fragments in the text by an enumerator

Posted: Thu Nov 29, 2012 8:11 pm
by shveicar980
Hello!
Tell me how to make the replacement of every meeting in html file type values image_3453.jpg to the value image_(enumerator).jpg
For example:
Searching - scheme image_ ([0-9] +). jpg replace the first value encountered in the text to image_001.jpg, replacing the second value encountered in the text to image_002.jpg, replacing the third value encountered in the text to image_003. jpg and so on.
For example there is a parameter [C]-enumerator in the program totalcommander but this program only works with file names.Perhaps provides commands for such cases in your program.
Thank you very much.

Re: Replacing fragments in the text by an enumerator

Posted: Fri Nov 30, 2012 8:46 am
by DataMystic Support
This is quite simple.

First, add a perl pattern filter, with pattern of

Code: Select all

Perl pattern [image_(\d+)\.jpg]
and Action - send variable 1 to subfilter.

Inside this filter, add a Filters\Special\Script (VBScript,JScript...), with the text below:

Code: Select all

      'Our line counter
      dim a
      
      'Called for every line in the file
      'EOL contains the end of line characters (Unix, DOS or Mac) that must be
      'appended to each line
      function processLine(line, EOL)
        a = a + 1
        processLine = a & EOL
      end function
      
      
      sub startJob()
        a = 0
      end sub
      
      
      sub endJob()
      end sub
      
      
      'Called before each file is opened -
      'perform per-file initialisation here
      function startFile()
        startFile = ""
      end function
      
      
      function endFile()
        endFile = ""
      end function
    

Re: Replacing fragments in the text by an enumerator

Posted: Fri Nov 30, 2012 8:06 pm
by shveicar980
Thanks for the help,but the numbering of the counter starts with 1 -
fragments derived form image_1.jpg image_2.jpg
What do I need do - to numbering was kind 001, 002 - that is image001.jpg image002.jpg and so on.I tried to change the parameter a = 0 for a = "000" still get the same result.
Obtained for all the files - one counter in your example.How to do so - to each individual file that has been added to the list of processing would be its own counter.
Thank you very much

Re: Replacing fragments in the text by an enumerator

Posted: Sat Dec 01, 2012 12:18 pm
by DataMystic Support
Happy to complete this task for you with a purchase of TextPipe Pro, or of consulting time if you are an existing customer.