Macro to split word and add hypen

Macro to split word and add hypen

12
Basic UserBasic User
12

    Mar 19, 2006#1

    Hi,

    I need to split some words and add hypen between them. The hyphen will be as a delimeter to verify that it is a single word in order to avoid being wrapped when displayed. This is to create a justify-aligned content.

    Below are some sample.

    BEFORE

    Welcome to the IDM Forum. This forum is meant as a user-to-user support mechanism. It is our desire that the use of this forum would promote and enable users to share the vast knowledge they jointly have with one another.

    AFTER

    Wel-co-me to the I-D-M Fo-rum. This fo-rum is me-ant as a u-ser--to--u-ser sup-port me-cha-nism. It is o-ur de-si-re that the u-se of this fo-rum wo-uld pro-mote and en-able u-sers to sha-re the vast know-ledge they jo-intly ha-ve with o-ne a-nother.

    Kindly advise on how to do this via UltraEdit?

    Thanks,

    6,677585
    Grand MasterGrand Master
    6,677585

      Mar 19, 2006#2

      I did not really understand what the macro should do. Could you edit your first post and modify the example to show how the lines look before and how they should look after the macro execution.

      UltraEdit has no informations about syllables of all words. So you have to create a big list of
      Find MatchWord PreserveCase "Keyword"
      Replace All "Key-word"

      macro commands in the macro or do you have already a file with such a find "Keyword" and replace with "Key-word" list.
      Best regards from an UC/UE/UES for Windows user from Austria

      12
      Basic UserBasic User
      12

        Mar 20, 2006#3

        Thank you Mofi for your feedback.

        I have updated the previous post with BEFORE and AFTER results.

        I guess the only way is to create a file with all the words in it and manually split the syllable and add the hypen symbol. This will be a library which can be used over and over.

        The macro function is only to do the Find & Replace tasks.

        Is there a batch replace where I can put all the words in a single plain-text file and UE will search and grab the text to replace from there?

        Example:

        The library of words in plain text file:

        Keyword[Key-word]
        keyword[key-word]
        Super[Su-per]
        super[su-per]
        Power[Po-wer]
        power[po-wer]


        The Macro will open the file and start searching and replacing all words with the one in the square bracket.

        Will UE able to do this? or do you have any other alternative?

        Thank you so much for your help.

        Regards,

        6,677585
        Grand MasterGrand Master
        6,677585

          Mar 20, 2006#4

          Yes, this could be done with a macro. The macro will need the macro property Continue if a Find with Replace not found. The words are saved in the file named "Wordlist.txt". You can change this name and add full path.

          The macro copies this file after some (security) preparations into the file to modify at top of this file. Then it marks the first line of the file to modify with a ">". You should not have a line in the wordlist.txt which starts with ">"!

          Next in a loop it does the replaces until the line starting with ">" is found (= end of wordlist replace block). You have to put in Wordlist.txt the words with all possible cases.

          You can add blank lines in the wordlist file for better reading (block building). Blank lines are ignored in the replace loop. Also all lines not ending with a ] are ignored in the replace loop so you can add also comment lines in the wordlist file. But make sure that no comment line starts with a ">".

          InsertMode
          ColumnModeOff
          HexOff
          Open "Wordlist.txt"
          Bottom
          IfColNum 1
          Else
          "
          "
          EndIf
          TrimTrailingSpaces
          SelectAll
          Clipboard 9
          Copy
          CloseFile NoSave
          Open "content.txt"
          Top
          Paste
          ">"
          Top
          Loop
          IfCharIs ">"
          Key DEL
          ExitLoop
          EndIf
          Key END
          IfColNum 1
          Key DEL
          Else
          Key LEFT ARROW
          IfCharIs "]"
          StartSelect
          Find Up Select "["
          Key RIGHT ARROW
          Copy
          EndSelect
          Key LEFT ARROW
          SelectToTop
          Find MatchCase MatchWord "^s"
          Replace All "^c"
          EndIf
          SelectLine
          Delete
          EndIf
          EndLoop
          ClearClipboard
          Clipboard 0
          Best regards from an UC/UE/UES for Windows user from Austria

          12
          Basic UserBasic User
          12

            Mar 20, 2006#5

            Thanks Mofi for your fast reply.

            Been reading your post over and over again to really understand it. Very complicated for a newbie like me. :P

            So sorry if what I ask below have already being answered before. I just need a clear guide on how to setup this Macro.

            Can the script be modified to fit below conditions?

            I have two text file. One is "wordlist.txt" (the word library) and the other is "content.txt" (the actual content which need to be split based on syllable). By doing this, I can store all words into one file and use it over and over again with other content.

            Below are the examples;

            Content in "wordlist.txt".
            Need to find the first word and replace with the one in square bracket.
            -----------------------------

            KEYWORD[KEY-WORD]
            SUPER[SU-PER]
            POWER[PO-WER]

            -----------------------------


            Content in file named "content.txt" BEFORE using Macro
            -----------------------------

            Keyword super power. POWER. Super. KEYWORD. Super Keyword Power.

            -----------------------------


            Content in file named "content.txt" AFTER using Macro
            -----------------------------

            Key-word su-per po-wer. PO-WER. Su-per. KEY-WORD. Su-per Key-word Po-wer.

            -----------------------------

            I need to replace more than one file, that is why I would prefer it to be this way. Will it be possible?

            Thank you for your kind advise.

            Regards,

            6,677585
            Grand MasterGrand Master
            6,677585

              Mar 20, 2006#6

              I have updated my previous post. I added opening the file content.txt and replaced find option PreserveCase with MatchCase. See red marked changes in the macro code.

              Your wordfile.txt must look as follows to get correct result in content.txt. The lines starting with a ; are comment lines which are allowed in the wordlist file and makes it easier to read and edit it. The lines starting with ; and the blank lines are ignored by the macro.

              -----------------------------
              ; all words uppercase
              KEYWORD[KEY-WORD]
              SUPER[SU-PER]
              POWER[PO-WER]

              ; all words capitalized
              Keyword[Key-word]
              Super[Su-per]
              Power[Po-wer]

              ; all words lowercase
              keyword[key-word]
              super[su-per]
              power[po-wer]
              -----------------------------

              If the macro works fine for you, add the command Save or CloseFile Save at the end of the macro to save content.txt without or with closing it.

              Without the command Open "content.txt" the macro would run always on current document. So you could open several files in UltraEdit, run the macro on the first file, after macro execution switch to next file, run the macro again, after macro execution switch to next file, run the macro again, ...

              You can automate this run on all open files also with an additional macro. Let's say you have named the macro "WordDivision" and have not added Open "content.txt".

              If you create one of the two following macros and also save this macro in the file with macro WordDivision, then macro WordDivision can be executed on all open files by simply executing this main macro once.


              Solution 1 for main macro which runs macro WordDivision on all open files:
              If you prefer to have all opened files still open after running the macro WordDivision on all open files with the main macro, do not add any save command to macro WordDivision without the command Open "content.txt". The main macro for this solution must have following code:

              InsertMode
              ColumnModeOff
              HexOff
              Top
              "MacroFirstFileMarker"
              Loop
              PlayMacro 1 "WordDivision"
              NextWindow
              Top
              Find MatchCase "MacroFirstFileMarker"
              IfFound
              Delete
              SaveAll
              ExitLoop
              EndIf
              EndLoop

              You can remove the SaveAll command if you want to save all your opened content files after macro execution manually.


              Solution 2 for main macro which runs macro WordDivision on all open files:
              Macro WordDivision without command Open "content.txt" and any save command is run on all open files and each file is closed after macro WordDivision has modified it. The main macro for this solution must have following code:

              Loop
              IfNameIs ""
              ExitLoop
              EndIf
              PlayMacro 1 "WordDivision"
              CloseFile Save
              EndLoop
              Best regards from an UC/UE/UES for Windows user from Austria

              12
              Basic UserBasic User
              12

                Mar 21, 2006#7

                Thank you so much Mofi for your detailed explaination.

                I will try to do it based on your explaination and post the results here.

                Again, thank you so much. UE & their support crew truly amazed me.

                Regards,