我想要一个能删除最后一个斜杠/斜杠的函数,现在我多次编写这段代码:
IF %variable:~-1%==\ SET variable=%variable:~0,-1%
所以我会像这样做
set var1=C:\Folder\
call :removeTrailingBackSlash var1
echo %var1%
- 我应该在这里看到“C:\ Folder”
答案 0 :(得分:1)
@ECHO OFF
SETLOCAL
SET var1=c:\somewhere\\\\\\\\\\\\
CALL :removeTrailingBackSlash var1
ECHO var1=%var1%
GOTO :eof
:removeTrailingBackSlash
IF NOT DEFINED %1 GOTO :eof
SETlocal
CALL SET $_=%%%1%%
IF %$_:~-1%==\ endlocal&CALL SET "%1=%%%1:~0,-1%%"&GOTO removeTrailingBackSlash
GOTO :eof
此过程应删除尾部反斜杠。它是如何工作的,我将作为练习留给读者:)