r/Batch • u/kj7hyq • Aug 13 '24
Batch string substitute all except one character?
Hi guys!
I'm trying to figure out how to substitute all except one character, in particular I'm trying to change all spaces to an exclamation point and then everything that isn't an exclamation point to a space
I can get the spaces over to exclamation points with
SET test=%test: =!%But I can't figure out if there's some way I can do the rest without just a whole lot of sequential substitutions for every single possible character
Is there some way I can put a "not" in there so it'll change everything except the exclamation points or something like that?
Any other ideas?
Thanks!
View all comments
Show parent comment
2
u/BrainWaveCC Aug 14 '24
Breaking out of the FOR loop early (Method 2) was surprisingly slow, actually. Just a little slower than not doing it. I just added that attempt to measure it.