• Login
Community
  • Login

How to replace spaces with another character?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 1.9k 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.
  • J
    Jarka Metelka
    last edited by Jul 16, 2019, 9:14 AM

    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

    E 1 Reply Last reply Jul 16, 2019, 10:45 AM Reply Quote 0
    • E
      Ekopalypse @Jarka Metelka
      last edited by Jul 16, 2019, 10:45 AM

      @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
      • J
        Jarka Metelka
        last edited by Jul 18, 2019, 7:51 AM

        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
        • G
          guy038
          last edited by guy038 Jul 18, 2019, 9:30 AM Jul 18, 2019, 9:14 AM

          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
          • J
            Jarka Metelka
            last edited by Jul 18, 2019, 9:27 AM

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