.bat文件创建具有特殊字符的复杂的字符串变量
问题描述:
我需要通过连接多个字符串创建一个字符串变量。最后一个字符串我需要的是如下
I need to create a single string variable by concatenating multiple strings. The final string i need is as below
<Workspace name="RealTimeRiskUSD_UA" path="C:\workspace" IsAdmin="false" />
这是我尝试过。
echo off
set path1="<Workspace "
set name="name="RealTimeRiskUSD_UA""
set path2="path="C:\workspace" IsAdmin="false" />"
set fullpath=%path1%%name%%path2%
echo %path1%
echo %name%
echo %path2%
echo %fullpath%
我使用下面的链接删除每个字符串双引号也试过,但不起作用结果
http://ss64.com/nt/syntax-esc.html
答
您可以使用SET的扩展语法。
设置VAR =内容。
You could use the extended syntax of SET. set "var=content".
这转义特殊字符,但引号不是字符串的一部分。
This escapes special characters, but the quotes aren't part of the string.
echo off
Setlocal EnableDelayedExpansion
set "path1=<Workspace "
set "name=name="RealTimeRiskUSD_UA""
set "path2=path="C:\workspace" IsAdmin="false" />"
set "fullpath=%path1%%name%%path2%"
echo !fullpath!