|
Answer» I have a variable:
SET X=%1
%1 contains "5.200901011259.Ken.job"
How can I remove any/all quotes from the varable?
Ken
Here is more information that might lead to an answer.
the program that calls this uses this line: FOR /f %%A in ('dir/b %QUEUES%\%QUEUE%\?.*.*.job') do call %BATCHQ%\exe\RunJob.exe %%A
The quotes are coming from this %%A.try this after seting the x var
Code: [Select]set x=%x:"=%http://www.dostips.com/DtTipsStringManipulation.php
C:\>type quote.bat
Code: [Select]echo off
setlocal enabledelayedexpansion
Rem %1 contains 'text"info"moretext' Rem How can I remove any/all quotes from the varable?
set x=%1 echo x = %x% set x=%x:~1,-1% echo x = %x% pause
set x=%x:"info"=info%
echo. x = %x%! Output : C:\> quote.bat 'text"info"moretext' x = 'text"info"moretext' x = text"info"moretext Press any key to continue . . . x = textinfomoretext C:\>http://www.dostips.com/DtTipsStringManipulation.php
C:\>type quote.bat
Code: [Select]echo off
setlocal enabledelayedexpansion
Rem %1 contains "5.200901011259.Ken.job"
Rem How can I remove any/all quotes from the varable?
set x=%1 echo x = %x% set x=%x:~1,-1% echo x = %x%
[/quote] Output :
C:\> quote.bat "5.200901011259.Ken.job"
x = "5.200901011259.Ken.job" x = 5.200901011259.Ken.job thanks guys, this one worked (in DOS and compiled in EXE)
set x=%1 set x=%x:~1,-1% what if you have extra quotes in between , eg
Code: [Select]"5.20090"101"1259.Ken.job" KENL,
Ghost and Dev are correct. Their code :
set x=%x:"=% set x=%x:'=%
is better than:
set x=%x:~1,-1%
( the above code only REMOVES quotes at the BEGINNING and end of the STRING.)
http://www.dostips.com/DtTipsStringManipulation.php
C:\>type quote.bat
Code: [Select]echo off
setlocal enabledelayedexpansion
Rem %1 contains 'text"info"moretext' Rem How can I remove any/all quotes from the varable?
set x=%1 echo x = %x% set x=%x:"=% set x=%x:'=% Rem set x=%x:~1,-1% echo x = %x% pause
Rem set x=%x:"info"=info%
echo. x = %x%!C:\> quote.bat 'text"info"moretext' x = 'text"info"moretext' x = textinfomoretext Press any key to continue . . . x = textinfomoretext
C:\>
|