如果我碰巧遇到了一个字符串,例如hello,我该如何从字符串中删除第n个字符?
我尝试了一下,但似乎不起作用(位置3):>
@ECHO ON
SET "input=%~1"
CALL :a input
SETLOCAL ENABLEDELAYEDEXPANSION
:a
SET "input=!%1!"
SET /A "position=3"
FOR /L %%a IN (!position!,1,!position!) DO (
SET /A "position2=%%a+1"
FOR /L %%b IN (!position2!,1,!position2!) DO (
ECHO "!input:~0,%%a!!input:~%%b!"
)
)
ENDLOCAL
答案 0 :(得分:0)
@ECHO off
SET "input=%~1"
CALL :a input
goto :EOF
:a
SETLOCAL ENABLEDELAYEDEXPANSION
SET "input=!%1!"
set /A "position=3, position2=position+1"
echo "!input:~0,%position%!!input:~%position2%!"
输出示例:
C:\Users\Antonio\Documents\Tests> test.bat hello
"helo"
在原始代码中,字符串在第一个参数中传递...