Document.ReplaceAll not working

Ask questions about how to create a script or swap scripts with other users.
Post Reply
kosthala
Posts: 49
Joined: 18 Feb 2014 21:36

Document.ReplaceAll not working

Post by kosthala »

Hello,

I have created a very simple Pascal script in order to remove trailing spaces:

Code: Select all

begin
  Document.ReplaceAll('^[ \t]+','', false, false, true);
end.
But when i run the script nothing happens. In previous versions the script was working fine.
Can you help me?
User avatar
Rickard Johansson
Site Admin
Posts: 6577
Joined: 19 Jul 2006 14:29

Re: Document.ReplaceAll not working

Post by Rickard Johansson »

To remove trailing white spaces you could use something like:

Code: Select all

Document.ReplaceAll("[ \\t]+$", "", false, false, true);

or

Document.ReplaceAll('[ \t]+$', '', false, false, true);  // Pascal
kosthala
Posts: 49
Joined: 18 Feb 2014 21:36

Re: Document.ReplaceAll not working

Post by kosthala »

I'm sorry, i meant leading spaces...which is not working

Code: Select all

begin
  Document.ReplaceAll('^[ \t]+','', false, false, true);
end.
User avatar
Rickard Johansson
Site Admin
Posts: 6577
Joined: 19 Jul 2006 14:29

Re: Document.ReplaceAll not working

Post by Rickard Johansson »

I can't see anything wrong. Maybe your not executing the script correctly...

For testing and developing:

1. Enable dual document view and open the script in the left pane.
2. Open a test file, to execute the script on, to the right.

Now, run the script.
kosthala
Posts: 49
Joined: 18 Feb 2014 21:36

Re: Document.ReplaceAll not working

Post by kosthala »

I followed your instructions and i get the attached message
Attachments
Capture.PNG
Capture.PNG (1.89 KiB) Viewed 13356 times
User avatar
Rickard Johansson
Site Admin
Posts: 6577
Joined: 19 Jul 2006 14:29

Re: Document.ReplaceAll not working

Post by Rickard Johansson »

If you create a new pascal script from the script menu you should get something like this:

Code: Select all

// Pascal script

// Global variables

// Enter code here
begin

end.
Insert your code between the begin .. end block.

E.g.

Code: Select all

// Pascal script

// Global variables

// Enter code here
begin
  Document.ReplaceAll('^[ \t]+','', false, false, true);
end.
kosthala
Posts: 49
Joined: 18 Feb 2014 21:36

Re: Document.ReplaceAll not working

Post by kosthala »

Please see my first post, i have already include begin - end pair.
User avatar
pjj
Posts: 2109
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Document.ReplaceAll not working

Post by pjj »

FWIW Rickard's script works for me well.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
kosthala
Posts: 49
Joined: 18 Feb 2014 21:36

Re: Document.ReplaceAll not working

Post by kosthala »

This is very weird. I copy the code from Rickard's script's and now is working.
But my first post script was exactly the same as Rickard's. :? :? :?
Post Reply