Community
    • Login

    How to replace characters over certain number?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 1.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      LordFader
      last edited by

      Hi,

      I have the following problem and I can’t get any further:

      I want to truncate text lines like this after 55 characters (with spaces) and replace them with " …".

      STOXX Europe 600 Optimised Personal & Household Goods EUR (Acc)
      MSCI EM Socially Responsible (Dist)
      STOXX Europe 600 Optimised Industrial Goods & Services EUR (Acc)

      So that the result looks as follows:
      STOXX Europe 600 Optimised Personal & Household Goods E …
      MSCI EM Socially Responsible (Dist)
      STOXX Europe 600 Optimised Industrial Goods & Services …

      I have tried the following, but it does not work:
      Highlights only the first 5 characters

      ^.{5}
      

      Finds “only” the last paragraph, no concrete character limit

      \h+\S+$
      

      What must the command look like that it works?
      (gladly with a short explanation what each operator does, then I understand the principle better)

      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        Hello, @till-ehrich and All,

        You said :

        I want to truncate text lines like this after 55 characters

        OK. Now, what about the 56th character ?

        If the 56th char is a space char, I suppose that you expect this replacement :

        1234567890123456789012345678901234567890123456789012345 …
        

        But, if the 56th char is not a space char, like below :

        1234567890123456789012345678901234567890123456789012345ABDEFG HIJKL MNO
        

        Do you expect this OUTPUT :

        1234567890123456789012345678901234567890123456789012345 …
        

        or this OUTPUT :

        1234567890123456789012345678901234567890123456789012345ABCDEFG …
        

        Best Regards,

        guy038

        L 1 Reply Last reply Reply Quote 0
        • L
          LordFader @guy038
          last edited by

          @guy038
          Whether there is a space or a character after the 55 character is not important. Then only the rest should be replaced by " …".

          ABCDE FGHIJ KLMNO
          ABCDE FGHIJKLMNO
          ABCDE FGHIJ  ...
          ABCDE FGHIJ ...
          

          If there is a blank character, one would have with a simple solution then " ..." at the end, thus with 2 blank characters behind each other. But I can change that in a second step simply with search and replace.

          1 Reply Last reply Reply Quote 0
          • guy038G
            guy038
            last edited by

            Hi, @till-ehrich and All,

            Ah…, OK. In this case, use the following regex S/R :

            • Open the Replace dialog ( Ctrl + H )

            • SEARCH (?-s).{55}\K.+

            • REPLACE \x20\x{2026}

            • Check the Wrap around box option, preferably

            • Select the Regular expression search mode

            • Click on the Replace All button ( Do not use the Replace button ! )

            BR

            guy038

            Alan KilbornA L 2 Replies Last reply Reply Quote 3
            • Alan KilbornA
              Alan Kilborn @guy038
              last edited by

              OP probably wants ... rather than \x{2026} in the replacement…

              1 Reply Last reply Reply Quote 2
              • L
                LordFader @guy038
                last edited by

                @guy038 said in How to replace characters over certain number?:

                (?-s).{55}\K.+

                Thank you very much, everything worked great. Tidy lists please the users :-)

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors