1

有谁知道如何从 DOS 批处理脚本中的字符串中去除引号字符?使用字符串替换功能可以轻松去除字符,但去除引号(或感叹号)似乎有点困难。这是我试图开始工作的测试脚本:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
echo.
set "NAME=Izomorphius"
call :append NAME " is my dear friend."
echo Message: %NAME%
echo.
goto :end
:: Functions
:append @varname @value
IF NOT "%3"=="" (
  echo Too many arguments to function.
)
set vara=%1
set stra=%2
set stra=%stra:""=%
set "%1=!%1! %2"
exit /B 0
:end
pause

这是此脚本的输出:

Message: Izomorphius " is my dear friend."
4

1 回答 1

2

修饰符将从参数中删除封闭的~引号。从命令提示符键入HELP CALL完整的修饰符列表。相同的修饰符也可用于 FOR 变量。

@echo off
setlocal enableDelayedExpansion
echo.
set "NAME=Izomorphius"
call :append NAME " is my dear friend."
echo Message: %NAME%
echo.
goto :end

:: Functions

:append @varname @value
IF NOT "%~3"=="" echo Too many arguments to function.
set "%~1=!%~1! %~2"
exit /B 0

:end
pause
于 2012-11-02T18:55:40.280 回答