How to replace spaces with another character?



  • 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



  • @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.



  • 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
    


  • 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



  • 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.


Log in to reply