Script for replacing placeholders in index with automatic numbered identifiers and references

Script for replacing placeholders in index with automatic numbered identifiers and references

13
Basic UserBasic User
13

    Jul 27, 2016#1

    Hi to all.

    My input is

    Code: Select all

    <a id="toc-intro" href="@@@.html#intro">
    <a id="toc-ack" href="@@@.html#ack">
    <a id="toc-ch1" href="@@@.html#ch1">
    I copy the word after "toc-" like intro and ack.
    But in the 3rd case I just copy the number after toc-ch.

    My code with the find is:

    Code: Select all

    UltraEdit.perlReOn();
    UltraEdit.activeDocument.findReplace.matchCase=true;
    UltraEdit.activeDocument.findReplace.regExp=true;
    UltraEdit.activeDocument.findReplace.searchDown=true;
    UltraEdit.activeDocument.findReplace.preserveCase=false;
    UltraEdit.activeDocument.findReplace.find("id=\"(toc-chapter|toc-ch|toc-part|toc-pt|toc-)");
    UltraEdit.clipboardContent = UltraEdit.activeDocument.findReplace.find("([^<>\"\r\n]*?)(?=\")");
    var nSec = UltraEdit.activeDocument.copy(UltraEdit.clipboardContent);
    And my replacement code is

    Code: Select all

    UltraEdit.activeDocument.findReplace.replace("@@",nSec);
    for replacing this code in file

    Code: Select all

    <a id="sec@@-##" href="@@@.html#sec@@_##">
    Please reply those codes are correct or not.

    6,681583
    Grand MasterGrand Master
    6,681583

      Jul 27, 2016#2

      Let us look together on data

      <a id="toc-ch1" href="@@@.html#ch1">

      to evaluate by Perl regular expression find string

      id="(toc-chapter|toc-ch|toc-part|toc-pt|toc-)

      The Perl regular expression search finds first id=" and starts now the evaluation of the OR expression (in a capturing group, non capturing group would be a little bit faster here).

      The first 6 characters of toc-chapter match with the data in the line, but 7th character is not matching. So the first argument of the OR expression does not result in a positive match.

      The Perl regular expression find function traces back to character after id=" and evaluates now the second argument toc-ch which indeed results in a 100% match. So second argument of OR expression is positive and as there is no more criteria for a positive match of entire search string after the OR expression, the task is done with finding id="toc-ch which is selected and caret is blinking after this string in the file.

      The next regular expression find should match everything from current position in file to " which is in this case just the character 1. So the script does what you coded, but what you don't want.

      Here is an improved code for your task to get the string of interest into a string variable. It uses a lookbehind and a lookahead to match just intro, ack and ch1 in right context, i.e. with id="toc- before and " as next character.

      Code: Select all

         UltraEdit.perlReOn();
         UltraEdit.activeDocument.findReplace.matchCase=true;
         UltraEdit.activeDocument.findReplace.regExp=true;
         UltraEdit.activeDocument.findReplace.searchDown=true;
         UltraEdit.activeDocument.findReplace.preserveCase=false;
         UltraEdit.activeDocument.findReplace.find('(?<=id="toc-).+?(?=")');
         var nSec = UltraEdit.activeDocument.selection; 
      
      Some more hints:

      In JavaScript a string can be defined either with "..." or with '...'. In a string defined with "..." a double quote which should be part of the string must be escaped with a backslash, but a single quote can be specified without a backslash. In a string defined with '...' a literal to interpret single quote must be escaped with a backslash, but a double quote can be specified without a backslash. For strings containing double quotes it is therefore much better to define the string with single quotes.

      The line var nSec = UltraEdit.activeDocument.copy(UltraEdit.clipboardContent); is nonsense in your code.
      The function UltraEdit.activeDocument.copy() does not take any parameter. This function copies always the selected text in active document to active clipboard. So UltraEdit.clipboardContent is completely ignored. The value returned to variable nSec is the boolean value true which does not mean that the copy was successful. The returned value is always true even if nothing was copied as nothing selected in active file. The property UltraEdit.clipboardContent (string member variable of UltraEdit object/class) has no effect here at all.

      To copy a string to active clipboard and assign the clipboard content later to a string variable the could would be:

      Code: Select all

      UltraEdit.activeDocument.copy();
      var sClipboardText = UltraEdit.clipboardContent;
      The variable name nSec looks like based on my naming convention, but used wrong. The prefix n means in my naming convention that the variable Sec holds a number (integer value), but in code above it holds a string and should be named sSec according to my naming convention. See this post if you are interested in my simple naming convention used for JavaScript which you can but must not use for your JavaScript code.
      Best regards from an UC/UE/UES for Windows user from Austria

      13
      Basic UserBasic User
      13

        Jul 27, 2016#3

        Thanks Mofi,

        but my script does not work properly due to this reason I post my script and my input. Please help me.

        The input is:

        Code: Select all

        <p><a id="toc-intro" href="@@@.html#intro"><em>Introduction</em></a></p>
        <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
        <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
        <p><a id="toc-ptI" href="@@@.html#ptI"><b>Part I Macro issues: the role and legitimacy of business activity</b></a></p>
        <p><span class="label"><a id="toc-ch1" href="@@@.html#ch1">1</a></span> <a href="@@@.html#ch1">BUSINESS PHILOSOPHY: SEARCHING FOR AN AUTHENTIC ROLE</a></p>
        <p><em>Text..</em></p>
        <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
        <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
        <p><span class="label"><a id="toc-ch2" href="@@@.html#ch2">2</a></span> <a href="@@@.html#ch2">WHOSE BUSINESS IS IT ANYWAY? &#x2013; THE QUESTION OF SUSTAINABILITY</a></p>
        <p><em>Text..</em></p>
        <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
        <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
        
        The output should be:

        Code: Select all

        <p><a id="toc-intro" href="@@@.html#intro"><em>Introduction</em></a></p>
        <p><a id="secintro-1" href="@@@.html#secintro_1"><em>Text..</em></a></p>
        <p><a id="secintro-2" href="@@@.html#secintro_2"><em>Text..</em></a></p>
        <p><a id="toc-ptI" href="@@@.html#ptI"><b>Part I Macro issues: the role and legitimacy of business activity</b></a></p>
        <p><span class="label"><a id="toc-ch1" href="@@@.html#ch1">1</a></span> <a href="@@@.html#ch1">BUSINESS PHILOSOPHY: SEARCHING FOR AN AUTHENTIC ROLE</a></p>
        <p><em>Text..</em></p>
        <p><a id="sec1-1" href="@@@.html#sec1_1"><em>Text..</em></a></p>
        <p><a id="sec1-2" href="@@@.html#sec1_2"><em>Text..</em></a></p>
        <p><span class="label"><a id="toc-ch2" href="@@@.html#ch2">2</a></span> <a href="@@@.html#ch2">WHOSE BUSINESS IS IT ANYWAY? &#x2013; THE QUESTION OF SUSTAINABILITY</a></p>
        <p><em>Text..</em></p>
        <p><a id="sec2-1" href="@@@.html#sec2_1"><em>Text..</em></a></p>
        <p><a id="sec2-2" href="@@@.html#sec2_2"><em>Text..</em></a></p>
        
        This my script:

        Code: Select all

        if (UltraEdit.document.length > 0)
        {
        	UltraEdit.insertMode();
        	UltraEdit.columnModeOff();
        	UltraEdit.activeDocument.top();
        	UltraEdit.activeDocument.selectAll();
        	if (UltraEdit.activeDocument.isSel())
        		{
        		UltraEdit.perlReOn();
        		UltraEdit.activeDocument.findReplace.matchCase=true;
        		UltraEdit.activeDocument.findReplace.regExp=true;
        		UltraEdit.activeDocument.findReplace.searchDown=true;
        		UltraEdit.activeDocument.findReplace.preserveCase=false;
        		UltraEdit.activeDocument.findReplace.replaceAll=true;
        		UltraEdit.activeDocument.findReplace.find('id=\"(toc-chapter|toc-ch|toc-part|toc-pt|toc-)');
        		UltraEdit.activeDocument.findReplace.find('([^<>\"\r\n]*?)(?=\")');
        		var sSec = UltraEdit.activeDocument.selection;
        		var asBlocks = UltraEdit.activeDocument.selection.split("id=\"toc");
        		var nBlockCount = asBlocks.length - 1;
        		for (var nBlock = 0; nBlock < nBlockCount; nBlock++)
        			{
        			var asEntries = asBlocks[nBlock].split("id=\"sec");
        			for (var nEntry = 1; nEntry < asEntries.length; nEntry++)
        				{
        				while (UltraEdit.activeDocument.findReplace.find('sec@@'))
        					{
        					UltraEdit.activeDocument.findReplace.replace("sec@@","sec"+sSec);
        					}
        				asEntries[nEntry] = asEntries[nEntry].replace("##",nEntry.toString(10));
        				asEntries[nEntry] = asEntries[nEntry].replace("##",nEntry.toString(10));
        				}
        			asBlocks[nBlock] = asEntries.join("id=\"sec");
        			}
        		UltraEdit.activeDocument.write(asBlocks.join("id=\"toc"));
        		UltraEdit.activeDocument.top();
        		}
        }
        
        After using my script the output is:

        <p><a id="toc-intro" href="@@@.html#intro"><em>Introduction</em></a></p>
        <p><a id="secsec@@-1" href="@@@.html#secsec@@_1"><em>Text..</em></a></p>
        <p><a id="secsec@@-2" href="@@@.html#secsec@@_2"><em>Text..</em></a></p>
        <p><a id="toc-ptI" href="@@@.html#ptI"><b>Part I Macro issues: the role and legitimacy of business activity</b></a></p>
        <p><span class="label"><a id="toc-ch1" href="@@@.html#ch1">1</a></span> <a href="@@@.html#ch1">BUSINESS PHILOSOPHY: SEARCHING FOR AN AUTHENTIC ROLE</a></p>
        <p><em>Text..</em></p>
        <p><a id="secsec@@-1" href="@@@.html#secsec@@_1"><em>Text..</em></a></p>
        <p><a id="secsec@@-2" href="@@@.html#secsec@@_2"><em>Text..</em></a></p>
        <p><span class="label"><a id="toc-ch2" href="@@@.html#ch2">2</a></span> <a href="@@@.html#ch2">WHOSE BUSINESS IS IT ANYWAY? &#x2013; THE QUESTION OF SUSTAINABILITY</a></p>
        <p><em>Text..</em></p>
        <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
        <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>


        Script doesn't work properly on colored portions.

        6,681583
        Grand MasterGrand Master
        6,681583

          Jul 27, 2016#4

          Okay, here is the script for your task.

          Code: Select all

          if (UltraEdit.document.length > 0)
          {
             UltraEdit.insertMode();
             UltraEdit.columnModeOff();
             UltraEdit.activeDocument.selectAll();
             if (UltraEdit.activeDocument.isSel())
             {
                var nTocNumber = 0;
                var nSecNumber = 0;
                var sTocIdentifier;
                var sSecIdentifier;
                var sSecReference;
          
                // Split up the file contents into blocks with using   id="toc
                // as block separator. The first block needs to be ignored as it
                // does not contain any data to process because being file header.
                var asTocBlocks = UltraEdit.activeDocument.selection.split('id="toc');
          
                for (var nBlock = 1; nBlock < asTocBlocks.length; nBlock++)
                {
                   // The identifier of the TOC block should be at beginning
                   // of the block and is the string up to first double quote.
                   var nQuotePos = asTocBlocks[nBlock].indexOf('"');
                   if (nQuotePos > 0)
                   {
                      sTocIdentifier = asTocBlocks[nBlock].substr(0,nQuotePos);
                   }
                   else  // For security define a TOC identifier if this
                   {     // TOC block has none for some unknown reason.
                      nTocNumber++;
                      sTocIdentifier = "-toc" + nTocNumber.toString(10);
                      if (nQuotePos == 0)
                      {
                         asTocBlocks[nBlock] = sTocIdentifier + asTocBlocks[nBlock];
                      }
                      else
                      {
                         asTocBlocks[nBlock] = sTocIdentifier + '"' + asTocBlocks[nBlock];
                      }
                   }
          
                   // Skip TOC blocks not containing any section identifier.
                   if (asTocBlocks[nBlock].indexOf('id="sec') < 0) continue;
          
                   // Determine section identifier and section reference for this TOC block.
                   if (sTocIdentifier == "-intro")
                   {
                      sSecIdentifier = "intro-";   // Intro block has different naming scheme.
                      sSecReference = "intro_";
                   }
                   else
                   {
                      nSecNumber++;
                      sSecIdentifier = nSecNumber.toString(10) + "-";
                      sSecReference = sSecIdentifier.replace("-","_");
                   }
          
                   // Split the TOC block with sections up into the sections and
                   // run a JavaScript regular expression replace on each section
                   // to replace template identifier and template reference by the
                   // current section based identifier and reference.
                   var asSections = asTocBlocks[nBlock].split('id="sec');
                   for (var nSection = 1; nSection < asSections.length; nSection++)
                   {
                      var sSection = nSection.toString(10);
                      var sReplace = sSecIdentifier + sSection + "$1" + sSecReference + sSection;
                      asSections[nSection] = asSections[nSection].replace(/sec@@-##(.+#sec)sec@@_##/,sReplace);
                   }
          
                   // Join the updated sections of the TOC block.
                   asTocBlocks[nBlock] = asSections.join('id="sec');
                }
          
                // Join the updated TOC blocks to file contents and overwrite file with it.
                UltraEdit.activeDocument.write(asTocBlocks.join('id="toc'));
                UltraEdit.activeDocument.top();
             }
          }
          
          Note: This script corrupts non ASCII characters in Unicode files because of the not good method UltraEdit uses to load Unicode text to a string variable. It would be possible to code this script completely different without loading complete file into memory, modify it there and output the complete updated file data back to the file. This alternate scripting solution I have in mind would work also for Unicode files with non ASCII characters in file.
          Best regards from an UC/UE/UES for Windows user from Austria

          13
          Basic UserBasic User
          13

            Jul 28, 2016#5

            Hi every one,
            Dear Mofi
            your script done really well.
            But have some little problem.

            1. Suppose
            <p><a id="toc-intro" href="@@@.html#intro"><em>Introduction</em></a></p>
            in this "toc-intro" is not fixed. Here different 'id' is in front of the matter.
            like

            Code: Select all

            <p><a id="toc-ack" href="@@@.html#ack"><em>Acknowledgements</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="toc-intro" href="@@@.html#intro"><em>Introduction</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="toc-bib" href="@@@.html#bib"><em>Bibliography</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="toc-ind" href="@@@.html#ind"><em>Index</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            2. Here alphabet or roman number also happen, after "ch"(chapter) or "pt"(part) in 'id'.
            like

            Code: Select all

            <p><a id="toc-ptI" href="@@@.html#ptI"><b>PART I Macro issues: the role and legitimacy of business activity</b></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            [code]<p><a id="toc-ptII" href="@@@.html#ptII"><b>PART II Text..</b></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><span class="label"><a id="toc-chA" href="@@@.html#chA">A</a></span> <a href="@@@.html#cha">CHAP: CORPORATE GOVERNANCE AND ETHICS</a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><span class="label"><a id="toc-ch1" href="@@@.html#ch1">1</a></span> <a href="@@@.html#ch1">BUSINESS PHILOSOPHY: SEARCHING FOR AN AUTHENTIC ROLE</a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            <p><a id="secsec@@-##" href="@@@.html#secsec@@_##"><em>Text..</em></a></p>
            Here this script generate only numeric value, no roman number or alphabet.

            Otherwise this script is excellent.
            Please looking this matter.
            I hope you understand my request.

            Actually after “toc” different id will happen, that I said my previous post.

            When id="toc-intro" then capture intro, but when id="toc-ptII",id="toc-ch1", id="toc-chA" happen then capture only those “numeric value, alphabetic value or roman number”.

            Due to this reason, I use those Perl expression as posted in first post.

            6,681583
            Grand MasterGrand Master
            6,681583

              Jul 28, 2016#6

              My script does not have any "problem". I wrote the script for you according to the examples in your second post and commented it accordingly. The output produced from the input is EXACTLY as you posted it. I verified it with a file compare of "output should be" example saved into a file named output.tmp with what the script produced saved as compare.tmp and the two files were 100% identical.

              Now you write the output is not what you expect which means the output you posted was not what you expect. Sorry, but I'm not a clairvoyant. As you might imagine, it does not make me happy spending my spare time coding a script for you producing EXACTLY what you asked for and read on next day that the script output is not what you want.

              In the two posts above there are two more input examples and part of a task description being additionally unclear. It would be perhaps really a good idea to look on my script read the comments and try to understand the few lines of the script. Then you could try to adapt it by yourself as often as needed until you know what you really want as output and the script produces exactly this output.

              If you want once again my help for the script, then post an input example containing all aspects which must be taken into account on script development and post for this input example what you want as output. And check line by line and character by character that the posted output is really what you want. I will spend my time only once writing another version of the script. There will be no third version written by me.
              Best regards from an UC/UE/UES for Windows user from Austria

              13
              Basic UserBasic User
              13

                Aug 04, 2016#7

                Dear Mofi,
                I am really thankful to you.

                My input is:

                Code: Select all

                <p><a id="toc-loc" href="@@@.html#loc"><em>List of Contributors</em></a></p>
                <p><a id="toc-ack" href="@@@.html#ack"><em>Acknowledgements</em></a></p>
                <p><a id="toc-in_tr-o" href="@@@.html#in_tr-o"><em>Introduction</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Introduction</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>A Western Christian theological perspective</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>An (industrial) democracy perspective</em></a></p>
                <p><a id="toc-pt_I" href="@@@.html#pt_I"><b>Part I Macro issues: the role and legitimacy of business activity</b></a></p>
                <p><a id="toc-abc" href="@@@.html#abc">1 BUSINESS PHILOSOPHY: SEARCHING FOR AN AUTHENTIC ROLE</a></p>
                <p><em>Peter W. F. Davies</em></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Introduction</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>A Western Christian theological perspective</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>An (industrial) democracy perspective</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>An (eco) systems perspective</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>A Friedmanite, &#x2018;the business of business is business&#x2019;, perspective</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>A virtues perspective</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Conclusions</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Notes</em></a></p>
                <p><a id="toc-ch.2" href="@@@.html#ch.2">2 WHOSE BUSINESS IS IT ANYWAY? &#x2013; THE QUESTION OF SUSTAINABILITY</a></p>
                <p><em>Raff Carmen and Marek Lubelski</em></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Introduction</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Genuine sustainablility v. competitive, &#x2018;business is business&#x2019;, survival</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>From &#x2018;how to have more&#x2019; to &#x2018;how much is enough?&#x2019;</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>The culture of power and the power of culture: the global civic society and sustainable development</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Ownership and control: the question ignored by business ethics</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Notes</em></a></p>
                <p><a id="toc-chthree" href="@@@.html#chthree">3 CORPORATE GOVERNANCE AND ETHICS</a></p>
                <p><em>Philip Stiles</em></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Introduction</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Key issues in corporate governance</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Self-regulation or legislation?</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Conclusion</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Notes</em></a></p>
                <p><a id="toc-forech" href="@@@.html#forech">4 BUSINESS AND ITS SOCIAL RESPONSIBILITY</a></p>
                <p><em>Andrew Wilson</em></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Introduction</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Discerning customers</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Discerning jobseekers</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Discerning investors</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Discerning employees</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Concluding remarks</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Notes</em></a></p>
                <p><a id="toc-2-part" href="@@@.html#2-part"><b>Part II Micro issues: the relationship between the individual and the business organisation</b></a></p>
                <p><a id="toc-poOa01p" href="@@@.html#poOa01p">5 THE BUSINESS ORGANISATION: A LOCUS FOR MEANING AND MORAL GUIDANCE</a></p>
                <p><em>Simon Webley</em></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Introduction</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Law of contract</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Business values</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>The value of staff</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Maintaining the rights of employees</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Ethical standard</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>What are the values of business?</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Practical guidance</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Issues in the future</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Summary</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Notes</em></a></p>
                <p><a id="toc-1a2s3a" href="@@@.html#1a2s3a">6 THE PSYCHOLOGICAL CONTRACT: ENACTING ETHICO-POWER</a></p>
                <p><em>Keith Pheby</em></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Introduction</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Autopoiesis and contextualised autonomy</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Ethico-power</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Notes</em></a></p>
                <p><a id="toc-OqwPO" href="@@@.html#OqwPO">7 ACTING PROFESSIONALLY: SOMETHING THAT BUSINESS ORGANISATIONS AND INDIVIDUALS BOTH DESIRE?</a></p>
                <p><em>Jane Pritchard</em></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Introduction</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Identifying the world of business</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>The professions</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>The values of business</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Managers are not professionals</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>The role of the in-house professional</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>The GP fundholder &#x2013; businessperson or professional?</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>The way forward is the way back</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Notes</em></a></p>
                <p><a id="toc-ch13ss" href="@@@.html#ch13ss">13 TRADE UNIONS AND ETHICS: UNIONS AS AGENTS</a></p>
                <p><em>Patrick Flood and Philip Stiles</em></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Introduction</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Monopoly power</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Collective voice: the union as agent</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Is non-unionism bad for employees?</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Unionism and new management techniques</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Employee representation</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Conclusion</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Acknowledgements</em></a></p>
                <p><a id="sec@@-##" href="@@@.html#sec@@_##"><em>Notes</em></a></p>
                <p><a id="toc-bib" href="@@@.html#bib"><em>Select annotated bibliography for further reading</em></a></p>
                <p><a id="toc-ind" href="@@@.html#ind"><em>Index</em></a></p>
                And my output is:

                Code: Select all

                <p><a id="toc-loc" href="@@@.html#loc"><em>List of Contributors</em></a></p>
                <p><a id="toc-ack" href="@@@.html#ack"><em>Acknowledgements</em></a></p>
                <p><a id="toc-in_tr-o" href="@@@.html#in_tr-o"><em>Introduction</em></a></p>
                <p><a id="secin_tr-o-1" href="@@@.html#secin_tr-o_1"><em>Introduction</em></a></p>
                <p><a id="secin_tr-o-2" href="@@@.html#secin_tr-o_2"><em>A Western Christian theological perspective</em></a></p>
                <p><a id="secin_tr-o-3" href="@@@.html#secin_tr-o_3"><em>An (industrial) democracy perspective</em></a></p>
                <p><a id="toc-pt_I" href="@@@.html#pt_I"><b>Part I Macro issues: the role and legitimacy of business activity</b></a></p>
                <p><a id="toc-abc" href="@@@.html#abc">1 BUSINESS PHILOSOPHY: SEARCHING FOR AN AUTHENTIC ROLE</a></p>
                <p><em>Peter W. F. Davies</em></p>
                <p><a id="secabc-1" href="@@@.html#secabc_1"><em>Introduction</em></a></p>
                <p><a id="secabc-2" href="@@@.html#secabc_2"><em>A Western Christian theological perspective</em></a></p>
                <p><a id="secabc-3" href="@@@.html#secabc_3"><em>An (industrial) democracy perspective</em></a></p>
                <p><a id="secabc-4" href="@@@.html#secabc_4"><em>An (eco) systems perspective</em></a></p>
                <p><a id="secabc-5" href="@@@.html#secabc_5"><em>A Friedmanite, &#x2018;the business of business is business&#x2019;, perspective</em></a></p>
                <p><a id="secabc-6" href="@@@.html#secabc_6"><em>A virtues perspective</em></a></p>
                <p><a id="secabc-7" href="@@@.html#secabc_7"><em>Conclusions</em></a></p>
                <p><a id="secabc-8" href="@@@.html#secabc_8"><em>Notes</em></a></p>
                <p><a id="toc-ch.2" href="@@@.html#ch.2">2 WHOSE BUSINESS IS IT ANYWAY? &#x2013; THE QUESTION OF SUSTAINABILITY</a></p>
                <p><em>Raff Carmen and Marek Lubelski</em></p>
                <p><a id="secch.2-1" href="@@@.html#secch.2_1"><em>Introduction</em></a></p>
                <p><a id="secch.2-2" href="@@@.html#secch.2_2"><em>Genuine sustainablility v. competitive, &#x2018;business is business&#x2019;, survival</em></a></p>
                <p><a id="secch.2-3" href="@@@.html#secch.2_3"><em>From &#x2018;how to have more&#x2019; to &#x2018;how much is enough?&#x2019;</em></a></p>
                <p><a id="secch.2-4" href="@@@.html#secch.2_4"><em>The culture of power and the power of culture: the global civic society and sustainable development</em></a></p>
                <p><a id="secch.2-5" href="@@@.html#secch.2_5"><em>Ownership and control: the question ignored by business ethics</em></a></p>
                <p><a id="secch.2-6" href="@@@.html#secch.2_6"><em>Notes</em></a></p>
                <p><a id="toc-chthree" href="@@@.html#chthree">3 CORPORATE GOVERNANCE AND ETHICS</a></p>
                <p><em>Philip Stiles</em></p>
                <p><a id="secchthree-1" href="@@@.html#secchthree_1"><em>Introduction</em></a></p>
                <p><a id="secchthree-2" href="@@@.html#secchthree_2"><em>Key issues in corporate governance</em></a></p>
                <p><a id="secchthree-3" href="@@@.html#secchthree_3"><em>Self-regulation or legislation?</em></a></p>
                <p><a id="secchthree-4" href="@@@.html#secchthree_4"><em>Conclusion</em></a></p>
                <p><a id="secchthree-5" href="@@@.html#secchthree_5"><em>Notes</em></a></p>
                <p><a id="toc-forech" href="@@@.html#forech">4 BUSINESS AND ITS SOCIAL RESPONSIBILITY</a></p>
                <p><em>Andrew Wilson</em></p>
                <p><a id="secforech-1" href="@@@.html#secforech_1"><em>Introduction</em></a></p>
                <p><a id="secforech-2" href="@@@.html#secforech_2"><em>Discerning customers</em></a></p>
                <p><a id="secforech-3" href="@@@.html#secforech_3"><em>Discerning jobseekers</em></a></p>
                <p><a id="secforech-4" href="@@@.html#secforech_4"><em>Discerning investors</em></a></p>
                <p><a id="secforech-5" href="@@@.html#secforech_5"><em>Discerning employees</em></a></p>
                <p><a id="secforech-6" href="@@@.html#secforech_6"><em>Concluding remarks</em></a></p>
                <p><a id="secforech-7" href="@@@.html#secforech_7"><em>Notes</em></a></p>
                <p><a id="toc-2-part" href="@@@.html#2-part"><b>Part II Micro issues: the relationship between the individual and the business organisation</b></a></p>
                <p><a id="toc-poOa01p" href="@@@.html#poOa01p">5 THE BUSINESS ORGANISATION: A LOCUS FOR MEANING AND MORAL GUIDANCE</a></p>
                <p><em>Simon Webley</em></p>
                <p><a id="secpoOa01p-1" href="@@@.html#secpoOa01p_1"><em>Introduction</em></a></p>
                <p><a id="secpoOa01p-2" href="@@@.html#secpoOa01p_2"><em>Law of contract</em></a></p>
                <p><a id="secpoOa01p-3" href="@@@.html#secpoOa01p_3"><em>Business values</em></a></p>
                <p><a id="secpoOa01p-4" href="@@@.html#secpoOa01p_4"><em>The value of staff</em></a></p>
                <p><a id="secpoOa01p-5" href="@@@.html#secpoOa01p_5"><em>Maintaining the rights of employees</em></a></p>
                <p><a id="secpoOa01p-6" href="@@@.html#secpoOa01p_6"><em>Ethical standard</em></a></p>
                <p><a id="secpoOa01p-7" href="@@@.html#secpoOa01p_7"><em>What are the values of business?</em></a></p>
                <p><a id="secpoOa01p-8" href="@@@.html#secpoOa01p_8"><em>Practical guidance</em></a></p>
                <p><a id="secpoOa01p-9" href="@@@.html#secpoOa01p_9"><em>Issues in the future</em></a></p>
                <p><a id="secpoOa01p-10" href="@@@.html#secpoOa01p_10"><em>Summary</em></a></p>
                <p><a id="secpoOa01p-11" href="@@@.html#secpoOa01p_11"><em>Notes</em></a></p>
                <p><a id="toc-1a2s3a" href="@@@.html#1a2s3a">6 THE PSYCHOLOGICAL CONTRACT: ENACTING ETHICO-POWER</a></p>
                <p><em>Keith Pheby</em></p>
                <p><a id="sec1a2s3a-1" href="@@@.html#sec1a2s3a_1"><em>Introduction</em></a></p>
                <p><a id="sec1a2s3a-2" href="@@@.html#sec1a2s3a_2"><em>Autopoiesis and contextualised autonomy</em></a></p>
                <p><a id="sec1a2s3a-3" href="@@@.html#sec1a2s3a_3"><em>Ethico-power</em></a></p>
                <p><a id="sec1a2s3a-4" href="@@@.html#sec1a2s3a_4"><em>Notes</em></a></p>
                <p><a id="toc-OqwPO" href="@@@.html#OqwPO">7 ACTING PROFESSIONALLY: SOMETHING THAT BUSINESS ORGANISATIONS AND INDIVIDUALS BOTH DESIRE?</a></p>
                <p><em>Jane Pritchard</em></p>
                <p><a id="secOqwPO-1" href="@@@.html#secOqwPO_1"><em>Introduction</em></a></p>
                <p><a id="secOqwPO-2" href="@@@.html#secOqwPO_2"><em>Identifying the world of business</em></a></p>
                <p><a id="secOqwPO-3" href="@@@.html#secOqwPO_3"><em>The professions</em></a></p>
                <p><a id="secOqwPO-4" href="@@@.html#secOqwPO_4"><em>The values of business</em></a></p>
                <p><a id="secOqwPO-5" href="@@@.html#secOqwPO_5"><em>Managers are not professionals</em></a></p>
                <p><a id="secOqwPO-6" href="@@@.html#secOqwPO_6"><em>The role of the in-house professional</em></a></p>
                <p><a id="secOqwPO-7" href="@@@.html#secOqwPO_7"><em>The GP fundholder &#x2013; businessperson or professional?</em></a></p>
                <p><a id="secOqwPO-8" href="@@@.html#secOqwPO_8"><em>The way forward is the way back</em></a></p>
                <p><a id="secOqwPO-9" href="@@@.html#secOqwPO_9"><em>Notes</em></a></p>
                <p><a id="toc-ch13ss" href="@@@.html#ch13ss">13 TRADE UNIONS AND ETHICS: UNIONS AS AGENTS</a></p>
                <p><em>Patrick Flood and Philip Stiles</em></p>
                <p><a id="secch13ss-1" href="@@@.html#secch13ss_1"><em>Introduction</em></a></p>
                <p><a id="secch13ss-2" href="@@@.html#secch13ss_2"><em>Monopoly power</em></a></p>
                <p><a id="secch13ss-3" href="@@@.html#secch13ss_3"><em>Collective voice: the union as agent</em></a></p>
                <p><a id="secch13ss-4" href="@@@.html#secch13ss_4"><em>Is non-unionism bad for employees?</em></a></p>
                <p><a id="secch13ss-5" href="@@@.html#secch13ss_5"><em>Unionism and new management techniques</em></a></p>
                <p><a id="secch13ss-6" href="@@@.html#secch13ss_6"><em>Employee representation</em></a></p>
                <p><a id="secch13ss-7" href="@@@.html#secch13ss_7"><em>Conclusion</em></a></p>
                <p><a id="secch13ss-8" href="@@@.html#secch13ss_8"><em>Acknowledgements</em></a></p>
                <p><a id="secch13ss-9" href="@@@.html#secch13ss_9"><em>Notes</em></a></p>
                <p><a id="toc-bib" href="@@@.html#bib"><em>Select annotated bibliography for further reading</em></a></p>
                <p><a id="toc-ind" href="@@@.html#ind"><em>Index</em></a></p>
                I write a script using your help.

                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('(?<="toc-).+?(?=")|sec@@-##|sec@@_##'))
                   {
                      if (UltraEdit.activeDocument.selection.substr(5,7) == "-##")
                      {
                         UltraEdit.activeDocument.write("sec");
                         UltraEdit.activeDocument.paste();
                         nNumber++;
                         UltraEdit.activeDocument.write("-" + nNumber.toString(10));
                      }
                      else if (UltraEdit.activeDocument.selection.substr(5,7) == "_##")
                      {
                         UltraEdit.activeDocument.write("sec");
                         UltraEdit.activeDocument.paste();
                         UltraEdit.activeDocument.write("_" + nNumber.toString(10));
                      }
                      else
                      {
                         nNumber = 0;
                         UltraEdit.activeDocument.copy();
                      }
                   }
                   UltraEdit.clearClipboard();
                   UltraEdit.selectClipboard(0);
                   UltraEdit.activeDocument.top();
                   UltraEdit.activeDocument.findReplace.replaceAll=true;
                   UltraEdit.activeDocument.findReplace.replace("sec(part|pt|chapter|ch)", "sec");
                   UltraEdit.activeDocument.top();
                }
                
                That works, but take more time.
                I would like to have any script that work quickly, and using split function?
                Please help me.

                6,681583
                Grand MasterGrand Master
                6,681583

                  Aug 04, 2016#8

                  Yes, I posted on the other topic from Samir (You? Same IP address!) the solution I had in mind working for Unicode files with Unicode characters. And you adapted the script code very well for this task.

                  Here is the code working completely in memory and being therefore faster, but corrupts the file contents if the file contains Unicode characters. I also simplified the code.

                  Code: Select all

                  if (UltraEdit.document.length > 0)
                  {
                     UltraEdit.insertMode();
                     UltraEdit.columnModeOff();
                     UltraEdit.activeDocument.selectAll();
                     if (UltraEdit.activeDocument.isSel())
                     {
                        var sTocIdentifier;
                        var sSecIdentifier;
                        var sSecReference;
                  
                        // Split up the file contents into blocks with using   id="toc-
                        // as block separator. The first block needs to be ignored as it
                        // does not contain any data to process because being file header.
                        var asTocBlocks = UltraEdit.activeDocument.selection.split('id="toc-');
                  
                        for (var nBlock = 1; nBlock < asTocBlocks.length; nBlock++)
                        {
                           // The identifier of the TOC block should be at beginning
                           // of the block and is the string up to first double quote.
                           var nQuotePos = asTocBlocks[nBlock].indexOf('"');
                  
                           if (nQuotePos < 1) continue;
                  
                           // Skip TOC blocks not containing any section identifier.
                           if (asTocBlocks[nBlock].indexOf('id="sec') < 0) continue;
                  
                           sTocIdentifier = asTocBlocks[nBlock].substr(0,nQuotePos).replace(/^(?:part|pt|chapter|ch)/,"");
                           sSecIdentifier = sTocIdentifier + "-";
                           sSecReference  = sTocIdentifier + "_";
                  
                           // Split the TOC block with sections up into the sections and
                           // run a JavaScript regular expression replace on each section
                           // to replace template identifier and template reference by the
                           // current section based identifier and reference.
                           var asSections = asTocBlocks[nBlock].split('id="sec');
                           for (var nSection = 1; nSection < asSections.length; nSection++)
                           {
                              var sSection = nSection.toString(10);
                              var sReplace = sSecIdentifier + sSection + "$1" + sSecReference + sSection;
                              asSections[nSection] = asSections[nSection].replace(/@@-##(.+#sec)@@_##/,sReplace);
                           }
                  
                           // Join the updated sections of the TOC block.
                           asTocBlocks[nBlock] = asSections.join('id="sec');
                        }
                  
                        // Join the updated TOC blocks to file contents and overwrite file with it.
                        UltraEdit.activeDocument.write(asTocBlocks.join('id="toc-'));
                        UltraEdit.activeDocument.top();
                     }
                  }
                  
                  Best regards from an UC/UE/UES for Windows user from Austria

                  13
                  Basic UserBasic User
                  13

                    Aug 05, 2016#9

                    Yes I and Samir Rajesh are colleagues in same company.
                    Thanks Mofi.
                    The script works exactly as I want it.