CMD DOS Example of taking QUOTES and SPACES out of variable
with special symbols
This example will take all the quotes and spaces out of a string
that has special characters “<” and “>” by utilizing DELAYED
EXPANSION. Delay Expansion means that
variables are not determined when the cmd file is parsed but at run time. This means that special characters “<” and
“>” are not treated as redirection characters.
Test.cmd:
@echo off
cls
setlocal ENABLEDELAYEDEXPANSION
ENABLEEXTENSIONS
set myvar="<add
key="MyKeyNameInQuotes"
value="https://MySSLSite.MyDomainName.com/WebServices"/>"
echo myvar ORIGINAL VALUE = !myvar!
set myvar=!myvar:"=!
echo myvar ALL QUOTES TAKEN OUT =
!myvar!
set myvar=!myvar: =!
echo myvar ALL SPACES TAKEN OUT =
!myvar!
goto:eof
|
OUTPUT:
myvar ORIGINAL VALUE =
"<add key="MyKeyNameInQuotes"
value="https://MySSLSite.MyDomainName.com/WebServices"/>"
myvar ALL QUOTES TAKEN OUT =
<add key=MyKeyNameInQuotes
value=https://MySSLSite.MyDomainName.com/WebServices/>
myvar ALL SPACES TAKEN OUT =
<addkey=MyKeyNameInQuotesvalue=https://MySSLSite.MyDomainName.com/WebServices/>
|
No comments:
Post a Comment