Community
    • Login

    How to replace characters over certain number?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 2.4k Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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 Offline
            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 Offline
              Alan Kilborn @guy038
              last edited by

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

              1 Reply Last reply Reply Quote 2
              • L Offline
                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

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors