Scripting help to change the case

Help with writing and running scripts

Scripting help to change the case

Postby amartin » Thu Aug 16, 2007 3:20 pm

I have a rather large output .ldif file I am having to change the case on one letter in several spots throughout the file. The letter that needs changed is different everytime, however, if I could search for a string then select the letter directly after the string and change its case I could pull it off.

I am pretty sure the answer to this question is to write a script but alas.. i am no javascript expert :)

are there any scripting junkies that could help me.

the string to look for would be : userpassword:

the letter directly after that would be uppercase and needs to be lowercase.

can anyone give me some quick help?

much thanks :)
User avatar
amartin
Newbie
 
Posts: 2
Joined: Wed Aug 15, 2007 11:00 pm

Re: Scripting help to change the case

Postby amartin » Thu Aug 16, 2007 5:36 pm

okay.. first off I want to give most of the credit for this to user thesmiths i stole most of this from his previous post about selecting text. http://www.ultraedit.com/index.php?name ... pic&t=5067

but i seem to have found the answer to my own question. I am sure this is not "clean" javascript .. but it did the job. figured i would post it here for anyone that needed a similar answer.

Code: Select all
//--------------------------------------
UltraEdit.outputWindow.showWindow(true);
UltraEdit.outputWindow.clear();

// start at top
UltraEdit.activeDocument.top();

// set search values
UltraEdit.activeDocument.findReplace.matchWord = false;

// loop to end of file
var done = false;
while (!UltraEdit.activeDocument.isEof() && !done)
{
   // find the start
   UltraEdit.activeDocument.findReplace.find("ord:");
   if (UltraEdit.activeDocument.isFound())
     {
        // found, now start the selection and then find the last char
        UltraEdit.activeDocument.key("RIGHT ARROW");
        UltraEdit.activeDocument.key("RIGHT ARROW");
        UltraEdit.activeDocument.key("RIGHT ARROW");
        UltraEdit.activeDocument.key("RIGHT ARROW");
        UltraEdit.activeDocument.startSelect();
        UltraEdit.activeDocument.key("RIGHT ARROW");
        if (UltraEdit.activeDocument.isFound())
        {
           // ok, have that, now grab the text
           UltraEdit.activeDocument.endSelect();
           UltraEdit.activeDocument.invertCase ();
        }
        else
        {
           // done
           done = true;
        }
   }
   else
   {
      // done
        done = true;
   }
}
//--------------------------------------
User avatar
amartin
Newbie
 
Posts: 2
Joined: Wed Aug 15, 2007 11:00 pm

Re: Scripting help to change the case

Postby jorrasdk » Thu Aug 16, 2007 6:48 pm

Hi amartin

There is an alternate solution. Since you are a version 13+ user, you are able to use Perl regular expressions.

In the UE help for Perl regular expressions it is noted that it implements Boost Libraries Perl Regular Expressions and from there you follow the trail to Perl 5.8.8 documentation and deep down you find:

Perl 5.8.8 documentation wrote: \l lowercase next char (think vi)
\u uppercase next char (think vi)
\L lowercase till \E (think vi)
\U uppercase till \E (think vi)
\E end case modification (think vi)


So in fact you could search for (remember to activate Perl regexp and to check the regular expression option in the search dialog):

(userpassword:)([A-Z])

and replace with

\1\l\2

Observe the \l which lowercase the next char.

Example before:
userpassword:Abcdef
userpassword:Ghijkl


and after replace:
userpassword:abcdef
userpassword:ghijkl

Jorrasdk
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark


Return to Scripts