catalinnc, Here is a one-liner that works with Prompt or .bat .
Although it functions within the limited scope that you described, it does break down if the character '!' is imbedded one or more times within a larger string. This is a middle approach that has no advantage other than to see if it could be done without going outside of plain batch script.
The above requires this file that I named Poison.bat :
Code: Select all
@Echo Off
SETLOCAL enabledelayedexpansion
set "DelChars== %% ^" ^^^^ ^^! ^< ^> ^& ^| "
set "DelChars=!DelChars: =!"
For /F "usebackq tokens=* delims=" %%I in ("%~1") DO (
set "str=A%%I"
set "len=0"
For /L %%A in (15,-1,0) do (
set /a "len|=1<<%%A"
for %%B in (!len!) do if "!str:~%%B,1!"=="" set /a "len&=~1<<%%A"
)
Set /A "pos=!len!-1"
Set "PoisonString=%%I"
IF "!PoisonString!" EQU "" (
Set PoisonString=^^!
set "pos=0"
)
For /L %%C in (0,1,8) do (
Set "Base=!DelChars:~%%C,1!"
For /L %%P in (!pos!,-1,0) do (
Set "Test=!PoisonString:~%%P,1!"
If /I "!Test!" EQU "!Base!" (
Set "Sterile= !Sterile!"
) Else (
Set "Sterile=!PoisonString:~%%P,1!!Sterile!"
)
)
Set "PoisonString=!Sterile!"
Set "Sterile="
)
If /I "%%I" EQU "" (
Rem. Echo.Panic^^!
Set "PoisonString= "
)
Echo.!PoisonString!
)
Exit /B
John A.