Scripting help to change the case

Scripting help to change the case

2
NewbieNewbie
2

    Aug 16, 2007#1

    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 every time. 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?

    Many thanks :)

      Aug 16, 2007#2

      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: Selecting number

      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;
         }
      }
      //--------------------------------------
      

      262
      MasterMaster
      262

        Aug 16, 2007#3

        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