Search for hard return in string with findreplace

Help with writing and running scripts

Search for hard return in string with findreplace

Postby Danh15 » Thu Nov 15, 2007 7:38 pm

In a script, I want to search for some text that has a hard return in it (DOS text file) and then delete it by replacing it with a null string "". The text is something like:

changetype: add <--- hard return after 'add'
loginDisabled:

If I put the following line in a script, it doesn't work:

UltraEdit.activeDocument.findReplace.replace("changetype: add
loginDisabled: ","");

If I use the ^p character to match the Hrt (like you can use in a normal find/replace), it doesn't work as well:

UltraEdit.activeDocument.findReplace.replace("changetype: add^ploginDisabled: ","");

Is it not possible to search for a string with hard returns or other control characters when using the findReplace command in a script?

Thanks,

Dan
User avatar
Danh15
Newbie
 
Posts: 4
Joined: Thu Nov 15, 2007 12:00 am

Re: Search for hard return in string with findreplace

Postby jorrasdk » Thu Nov 15, 2007 9:05 pm

I could reproduce the same reaction from UE as you described for the one line script.

UltraEdit.activeDocument.findReplace.replace("changetype: add^ploginDisabled:","");


but when I added some initializing to some of the findReplace options and the regular expression engine it worked ok. I haven't experimented with which option was needed from these:

UltraEdit.ueReOn();
UltraEdit.activeDocument.findReplace.regExp=false;
UltraEdit.activeDocument.findReplace.replaceAll=false;
UltraEdit.activeDocument.findReplace.replace("changetype: add^ploginDisabled:","");


Go figure. I think it can't hurt to ensure all options are set as you need them without assuming they are set as needed.

(And just to be sure: You also have a blank following the colon in loginDisabled: so there must be a blank in the data but I can't tell if this is true from your example).
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: Search for hard return in string with findreplace

Postby Danh15 » Thu Nov 15, 2007 10:00 pm

Thanks. I'll add those options. Yes, there is a blank following the colon in the file I am working on.

So it looks like you can embed the ^p, ^t, etc right in the text like you would if you were manually searching for it?

Also, is there any way to get the script to pause and then continue after some user input? So I would like to start the script, have it search for some known text, then turn on select and pause while I move the cursor to the end of the text I want selected (since it changes) then when I hit enter the script continues doing what I have programmed it to do. Is this possible?

Dan
User avatar
Danh15
Newbie
 
Posts: 4
Joined: Thu Nov 15, 2007 12:00 am

Re: Search for hard return in string with findreplace

Postby jorrasdk » Thu Nov 15, 2007 10:11 pm

I haven't experimented with changing cursor position in a document while a running script is paused by getString, getValue or messageBox. Open UE help and read about these script commands. If you experiment with these in your script, perhaps you can report back to us how it went ?!

And yes: ^p, ^t, ^n can be used in script exactly like in normal search/replace.
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark


Return to Scripts