Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch - replacing with percent symbol

I want to replace "mod" in string with "%":
set string=%string:mod=x%
What I should input as "x"?

like image 734
Michał R. Avatar asked Jan 05 '23 20:01

Michał R.


1 Answers

you can do that by enabling delayed expansion so you can use ! as delimiters. Then, doubling the percent sign allows to represent percent as a replacement char.

@echo off
setlocal enabledelayedexpansion

set string=12 mod 15
set string=!string:mod=%%!
echo %string%

result

12 % 15
like image 121
Jean-François Fabre Avatar answered Jan 12 '23 06:01

Jean-François Fabre