• Login
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 Feb 14, 2023, 1:18 PM

    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
    • G
      guy038
      last edited by guy038 Feb 14, 2023, 2:05 PM Feb 14, 2023, 1:55 PM

      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 Feb 14, 2023, 2:05 PM Reply Quote 0
      • L
        LordFader @guy038
        last edited by Feb 14, 2023, 2:05 PM

        @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
        • G
          guy038
          last edited by Feb 14, 2023, 2:22 PM

          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

          A L 2 Replies Last reply Feb 14, 2023, 2:27 PM Reply Quote 3
          • A
            Alan Kilborn @guy038
            last edited by Feb 14, 2023, 2:27 PM

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

            1 Reply Last reply Reply Quote 2
            • L
              LordFader @guy038
              last edited by Feb 14, 2023, 3:14 PM

              @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
              5 out of 6
              • First post
                5/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors