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 -
it is not very clear to me what exactly you want to have.
Assume a text like thisword1 word2should the result now
word1;;;;word2or
word1;word2or
word1; word2Btw. 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.
- 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- 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- 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- 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
spacecharacters ( So>= 2) with a character or string, use the following regex S/R-
SEARCH
\x20{2,} -
REPLACE
; -
Select the
Regular expressionsearch mode -
Tick the
Wrap aroundoption -
Click once on the
Replace Allbutton or several times on theReplacebutton
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,00We 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,00Note, however, that there is a slight difference with your output :
In your output, the
TUNIK 15167107zone is replaced asTUNIK;15167107! From the rule, as there is ONLY ONE space between the two words, it should NOT have been changed into asemi-colonsymbol ;-))
Now, to insert a
spacechar, at theNthposition, of any line,containing, at least,Nstandard 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 expressionsearch mode -
Tick the
Wrap aroundoption -
Click on the
Replace Allbutton, exclusively, because of the\Kfeature
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,00You’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,00Best 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.
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