Tapatalk

Insert name with sequence number

Insert name with sequence number

62
Advanced UserAdvanced User
62

    Jul 31, 2016#1

    Hi everyone,

    I have a task.

    Input

    Code: Select all

    Head of the Family "Aadi" [most important] Hindu
    • __'s son Aadinath [The first god] Boy Hindu
    • __'s son Aaditya [The sun] Boy Hindu
    • __'s son Aadit [Peak] Boy Hindu
    Head of the Family "Jhons" [A fiery young man] Christian
    Head of the Family "Aadil(Adil)" [Justice] Muslim
    • __'s son Azim [Justice] Boy Muslim
    • __'s son Salman [Attraction] Boy Muslim
    Head of the Family "Aäidan" [A fiery young man] Christian
    • __'s son Aaditeya [Origin] Boy Christian
    • __'s son James [Origin] Boy Christian
    Head of the Family "Z[J]ahir" [Justice] Muslim
    • __'s son Sadiqu [Strong] Boy Muslim

    Output

    Code: Select all

    Head of the Family "Aadi" [most important] Hindu
    1 Aadi's son Aadinath [The first god] Boy Hindu
    2 Aadi's son Aaditya [The sun] Boy Hindu
    3 Aadi's son Aadit [Peak] Boy Hindu
    Head of the Family "Jhons" [A fiery young man] Christian
    Head of the Family "Aadil(Adil)" [Justice] Muslim
    1 Aadil(Adil)'s son Azim [Justice] Boy Muslim
    2 Aadil(Adil)'s son Salman [Attraction] Boy Muslim
    Head of the Family "Aäidan" [A fiery young man] Christian
    1 Aäidan's son Aaditeya [Origin] Boy Christian
    2 Aäidan's son James [Origin] Boy Christian
    Head of the Family "Z[J]ahir" [Justice] Muslim
    1 Z[J]ahir's son Sadiqu [Strong] Boy Muslim
    
    Please help me, how to insert head of the family name (like above example Head of the Family "Aadi") before every child names and insert sequence number (like above example 1. Aadi's son Aadinath The first god Boy Hindu).

    I want to be number sequence single digit (1, 2, ...)

    Also if I want the other conversation of number sequence with leading zero like 5 digit (00001, 00002, ...)

    6,685587
    Grand MasterGrand Master
    6,685587

      Aug 02, 2016#2

      The script below uses for each family name the user clipboard 9 to work also for names with 1 or more Unicode characters in name.

      Code: Select all

      if (UltraEdit.document.length > 0)
      {
         UltraEdit.insertMode();
         UltraEdit.columnModeOff();
         UltraEdit.activeDocument.top();
      
         UltraEdit.perlReOn();
         UltraEdit.activeDocument.findReplace.mode=0;
         UltraEdit.activeDocument.findReplace.matchCase=false;
         UltraEdit.activeDocument.findReplace.matchWord=false;
         UltraEdit.activeDocument.findReplace.regExp=true;
         UltraEdit.activeDocument.findReplace.searchDown=true;
         UltraEdit.activeDocument.findReplace.searchInColumn=false;
      
         var nNumber = 0;
         UltraEdit.selectClipboard(9);
      
         while (UltraEdit.activeDocument.findReplace.find('(?<=Head of the Family ").+?(?=")|\\x{2022} __'))
         {
            if (UltraEdit.activeDocument.selection.substr(2) == "__")
            {
               nNumber++;
               UltraEdit.activeDocument.write(nNumber.toString(10) + " ");
               UltraEdit.activeDocument.paste();
            }
            else
            {
               nNumber = 0;
               UltraEdit.activeDocument.copy();
            }
         }
         UltraEdit.clearClipboard();
         UltraEdit.selectClipboard(0);
         UltraEdit.activeDocument.top();
      }
      
      Here is also nearly the same code as above with the small modification to output the sequence number always with at least 5 digits with up to 4 leading zeros depending on value of number.

      Code: Select all

      if (UltraEdit.document.length > 0)
      {
         UltraEdit.insertMode();
         UltraEdit.columnModeOff();
         UltraEdit.activeDocument.top();
      
         UltraEdit.perlReOn();
         UltraEdit.activeDocument.findReplace.mode=0;
         UltraEdit.activeDocument.findReplace.matchCase=false;
         UltraEdit.activeDocument.findReplace.matchWord=false;
         UltraEdit.activeDocument.findReplace.regExp=true;
         UltraEdit.activeDocument.findReplace.searchDown=true;
         UltraEdit.activeDocument.findReplace.searchInColumn=false;
      
         var nNumber = 0;
         var sLeadingZeros = "00000";
         UltraEdit.selectClipboard(9);
      
         while (UltraEdit.activeDocument.findReplace.find('(?<=Head of the Family ").+?(?=")|\\x{2022} __'))
         {
            if (UltraEdit.activeDocument.selection.substr(2) == "__")
            {
               nNumber++;
               var sNumber = nNumber.toString(10);
               sNumber = sLeadingZeros.substr(sNumber.length) + sNumber;
               UltraEdit.activeDocument.write(sNumber + " ");
               UltraEdit.activeDocument.paste();
            }
            else
            {
               nNumber = 0;
               UltraEdit.activeDocument.copy();
            }
         }
         UltraEdit.clearClipboard();
         UltraEdit.selectClipboard(0);
         UltraEdit.activeDocument.top();
      }
      
      Best regards from an UC/UE/UES for Windows user from Austria

      62
      Advanced UserAdvanced User
      62

        Aug 03, 2016#3

        Thanks Mofi

        you are just awesome............................ :P

          Aug 03, 2016#4

          Hi Mofi,

          Your script work properly.

          But when,
          I try to modify this script for
          this
          Input

          Code: Select all

          Head of the Family "Aadi" [most important] Hindu
          __'s • son Aadinath [The first god] Boy Hindu
          __'s • son Aaditya [The sun] Boy Hindu
          __'s • son Aadit [Peak] Boy Hindu
          Head of the Family "Jhons" [A fiery young man] Christian
          Head of the Family "Aadil(Adil)" [Justice] Muslim
          __'s • son Azim [Justice] Boy Muslim
          __'s • son Salman [Attraction] Boy Muslim
          Head of the Family "A&#x00E4;idan" [A fiery young man] Christian
          __'s • son Aaditeya [Origin] Boy Christian
          __'s • son James [Origin] Boy Christian
          Head of the Family "Z[J]ahir" [Justice] Muslim
          __'s • son Sadiqu [Strong] Boy Muslim
          My Modify script

          Code: Select all

              if (UltraEdit.document.length > 0)
              {
                 UltraEdit.insertMode();
                 UltraEdit.columnModeOff();
                 UltraEdit.activeDocument.top();
          
                 UltraEdit.perlReOn();
                 UltraEdit.activeDocument.findReplace.mode=0;
                 UltraEdit.activeDocument.findReplace.matchCase=false;
                 UltraEdit.activeDocument.findReplace.matchWord=false;
                 UltraEdit.activeDocument.findReplace.regExp=true;
                 UltraEdit.activeDocument.findReplace.searchDown=true;
                 UltraEdit.activeDocument.findReplace.searchInColumn=false;
          
                 var nNumber = 0;
                 UltraEdit.selectClipboard(9);
          
                 while (UltraEdit.activeDocument.findReplace.find('(?<=Head of the Family ").+?(?=")|__\'s \\x{2022}'))
                 {
                    if (UltraEdit.activeDocument.selection.substr(2) == "__")
                    {
                       nNumber++;
                       UltraEdit.activeDocument.paste();
                       UltraEdit.activeDocument.write("\'s " + nNumber.toString(10));
                    }
                    else
                    {
                       nNumber = 0;
                       UltraEdit.activeDocument.copy();
                    }
                 }
                 UltraEdit.clearClipboard();
                 UltraEdit.selectClipboard(0);
                 UltraEdit.activeDocument.top();
              }
          
          but not work this script

          My expected Output s/b

          Code: Select all

          Head of the Family "Aadi" [most important] Hindu
          Aadi's 1 son Aadinath [The first god] Boy Hindu
          Aadi's 2 son Aaditya [The sun] Boy Hindu
          Aadi's 3 son Aadit [Peak] Boy Hindu
          Head of the Family "Jhons" [A fiery young man] Christian
          Head of the Family "Aadil(Adil)" [Justice] Muslim
          Aadil(Adil)'s 1 son Azim [Justice] Boy Muslim
          Aadil(Adil)'s 2 son Salman [Attraction] Boy Muslim
          Head of the Family "A&#x00E4;idan" [A fiery young man] Christian
          A&#x00E4;idan's 1 son Aaditeya [Origin] Boy Christian
          A&#x00E4;idan's 2 son James [Origin] Boy Christian
          Head of the Family "Z[J]ahir" [Justice] Muslim
          Z[J]ahir's 1 son Sadiqu [Strong] Boy Muslim
          Please tell me some guideline

          6,685587
          Grand MasterGrand Master
          6,685587

            Aug 03, 2016#5

            \\x{2022} __ finds a string with 4 characters with third and fourth character (character index 2 and 3) are two underscores. The other part of the Perl OR expression finds the family name which is expected not having 4 characters with the last two being two underscores.

            Now let us look on the line:

            Code: Select all

                  if (UltraEdit.activeDocument.selection.substr(2) == "__")
            This condition gets from selected string the substring starting from character index 2 up to end of the selected string and compares it with a string consisting of exactly two underscores. If this condition is true, the found string is not a family name, but the placeholder for the family name.

            The Perl regular expression search string __\'s \\x{2022} finds now a string starting with 2 underscores and having a length of 6 characters. For that reason 's • is compared with __ which is never true.

            The solution is using this condition in your modified script:

            Code: Select all

                  if (UltraEdit.activeDocument.selection.substr(0,2) == "__")
            Now the first two characters of selected string are compared with exactly two underscores which is true if not a family name is currently selected.

            See String.prototype.substr() for a description of this core function of JavaScript String object.
            Best regards from an UC/UE/UES for Windows user from Austria

            62
            Advanced UserAdvanced User
            62

              Aug 04, 2016#6

              Thanks again Mofi ........................ :P :P