Community
    • Login

    How to replace spaces with another character?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 2.5k 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.
    • Jarka MetelkaJ Offline
      Jarka Metelka
      last edited by

      Greetings how to replace more than 1 space in the text (> = 2) eg “;”. I did it sequentially from behind (20 spaces, 19 spaces, 18 spaces, etc.) and a second question. How to put a character on a particular place in the same line to move the entire text. I just don’t want to rewrite it. Thank you.
      015 MYD 015 MYD TRIKO 015 MYD 1 ks 21 0,00 0,00 347,11 420,00
      1004 MAKR 1004 DAMSKE TRICKO HNEDY V MAKR 1 ks 21 0,00 0,00 570,25 690,00

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE Offline
        Ekopalypse @Jarka Metelka
        last edited by

        @Jarka-Metelka

        it is not very clear to me what exactly you want to have.
        Assume a text like this

        word1        word2
        

        should the result now

        word1;;;;word2
        

        or

        word1;word2
        

        or

        word1; word2
        

        Btw. if you post sample text, use three tildes before and after the sample text, this
        ensures that the formatting is kept. Something like ~~~ text ~~~.
        And for better understanding it is always nice if one posts a before and after sample.

        1 Reply Last reply Reply Quote 2
        • Jarka MetelkaJ Offline
          Jarka Metelka
          last edited by

          Thank you, I’m sorry, I’m a beginner. Perhaps it will be fine now.

          1. input
           15167107 TUNIK 15167107 TUNIKA             ONLY                8 ks  21    350,00    423,50    701,65    849,00
           15167115 ŠATY  15167115 ŠATY               ONLY                2 ks  21    490,00    592,90    983,47   1190,00
          
          1. output
           15167107 TUNIK;15167107 TUNIKA;ONLY;8 ks;21;350,00;423,50;701,65;849,00
           15167115 ŠATY;15167115 ŠATY;ONLY;2 ks;21;490,00;592,90;983,47;1190,00
          
          1. input
           15167107 TUNIK 15167107 TUNIKA             ONLY                8 ks  21    350,00    423,50    701,65    849,00
           15167115 ŠATY  15167115 ŠATY               ONLY                2 ks  21    490,00    592,90    983,47   1190,00
          
          1. output For example, insert a space at the 9th position of the text
           15167107  TUNIK 15167107 TUNIKA             ONLY                8 ks  21    350,00    423,50    701,65    849,00
           15167115  ŠATY  15167115 ŠATY               ONLY                2 ks  21    490,00    592,90    983,47   1190,00
          
          1 Reply Last reply Reply Quote 0
          • guy038G Offline
            guy038
            last edited by guy038

            Hello, @jarka-metelka, @ekopalypse and All,

            To replace several space characters ( So >= 2 ) with a character or string, use the following regex S/R

            • SEARCH \x20{2,}

            • REPLACE ;

            • Select the Regular expression search mode

            • Tick the Wrap around option

            • Click once on the Replace All button or several times on the Replace button

            So from the text :

             15167107 TUNIK 15167107 TUNIKA             ONLY                8 ks  21    350,00    423,50    701,65    849,00
             15167115 ŠATY  15167115 ŠATY               ONLY                2 ks  21    490,00    592,90    983,47   1190,00
            

            We should get :

             15167107 TUNIK 15167107 TUNIKA;ONLY;8 ks;21;350,00;423,50;701,65;849,00
             15167115 ŠATY;15167115 ŠATY;ONLY;2 ks;21;490,00;592,90;983,47;1190,00
            

            Note, however, that there is a slight difference with your output :

            In your output, the TUNIK 15167107 zone is replaced as TUNIK;15167107 ! From the rule, as there is ONLY ONE space between the two words, it should NOT have been changed into a semi-colon symbol ;-))


            Now, to insert a space char, at the Nth position, of any line,containing, at least, N standard characters, use the generic regex S/R, below :

            • SEARCH (?-s)^.{N}\K

            • REPLACE \x20

            In your case, the regex becomes (?-s)^.{9}\K

            • Select the Regular expression search mode

            • Tick the Wrap around option

            • Click on the Replace All button, exclusively, because of the \K feature

            So, from :

             15167107 TUNIK 15167107 TUNIKA             ONLY                8 ks  21    350,00    423,50    701,65    849,00
             15167115 ŠATY  15167115 ŠATY               ONLY                2 ks  21    490,00    592,90    983,47   1190,00
            

            You’ll obtain :

             15167107  TUNIK 15167107 TUNIKA             ONLY                8 ks  21    350,00    423,50    701,65    849,00
             15167115  ŠATY  15167115 ŠATY               ONLY                2 ks  21    490,00    592,90    983,47   1190,00
            

            So, if you applied the first regex S/R, against this output, we get, this time :

             15167107;TUNIK 15167107 TUNIKA;ONLY;8 ks;21;350,00;423,50;701,65;849,00
             15167115;ŠATY;15167115 ŠATY;ONLY;2 ks;21;490,00;592,90;983,47;1190,00
            

            Best Regards,

            guy038

            1 Reply Last reply Reply Quote 2
            • Jarka MetelkaJ Offline
              Jarka Metelka
              last edited by

              Thanks a lot, that’s exactly what I need. I know about the difference in the first example, so first I need to apply the space insertion and then replace more than 2 spaces with a semicolon.

              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