SoFunction
Updated on 2025-04-06

Batch processing code that removes all 0 before specified characters

As text:

Code:
0000acb0h
0b0c00a000s
0000h00ga00
a0000000
The output is as follows:
 
Code:
acb0h
bca000s
hga00
a0000000
Requirements: The code is concise, efficient, and universal, and no temporary files are generated

pusofalse:
Copy the codeThe code is as follows:

@echo off
for /f "delims=" %%. in () do (
set "str=%%."
call,set "str=%%str:*a=%%"
for /f "delims=a" %%{ in ("%%.") do (
set "var=%%{"
call,echo.%%var:0=%%a%%str%%
))
pause>nul

 

batman:
Copy the codeThe code is as follows:

@echo off
for /f "tokens=1,2 delims=a" %%i in () do (
if "%%j" neq "" (
set "str=%%i"
call,set "str=%%str:0=%%"
call,echo %%str%%a%%j
) else (
echo a%%i
)
)
pause>nul

The reason why batch processing is so popular is that it can be written and used easily.
At the same time, we are required to treat specific issues from another level, and I believe no one will
Let's write a code that is suitable for all such problems to solve a common problem
Well, if you really want to do this, the loss in time will be an incalculable loss, I
We will also lose more than we get.