dpichett
asked on
String concatenation in Windows batch file?
If I have environmental variables like:
X3DESTDIR="C:\Destination Folder"
X4DESTFIL="\zzzfiles\Subfo lderLevel2 \Subfolder Level3\fil e 553.zzz"
how can the two strings be concatenated. The use of percent signs like
SET FINAL_DEST=%DESTDIR%%DESTF IL%
results in extranneous quotes, i.e.
FINAL_DEST="C:\Destination Folder""\zzzfiles\Subfolde rLevel2\Su bfolderLev el3\file 553.zzz"
How to eliminate the extra quotes ("") in the middle of the result?
X3DESTDIR="C:\Destination Folder"
X4DESTFIL="\zzzfiles\Subfo
how can the two strings be concatenated. The use of percent signs like
SET FINAL_DEST=%DESTDIR%%DESTF
results in extranneous quotes, i.e.
FINAL_DEST="C:\Destination
How to eliminate the extra quotes ("") in the middle of the result?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Zyloch,
Thanks for the feedback, I don't want to strip out the quotes, I need the quotes to handle spaces in the folder and directory names.
Essentially, I'm looking for syntax that will take the strings "John Q." and " Public" and produce "John Q. Public", rather than "John Q."" Public"
Further thoughts?
Thanks for the feedback, I don't want to strip out the quotes, I need the quotes to handle spaces in the folder and directory names.
Essentially, I'm looking for syntax that will take the strings "John Q." and " Public" and produce "John Q. Public", rather than "John Q."" Public"
Further thoughts?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Similarly, my solution above removes all the quotes from both variables, slaps the variables together, and then puts quotes back on the ends.
-Brian
-Brian
The advantage of this solution is:
If the FINAL_DEST variable does not have any "" substring it will do nothing. If "" substring exists it will be deleted.
If the FINAL_DEST variable does not have any "" substring it will do nothing. If "" substring exists it will be deleted.
My solution is overkill, but I love overkill :)
Also, I neglected to slap quotes back on results:
call :CONCAT FINAL_DEST %X3DESTDIR% %X4DESTFIL%
set FINAL_DEST="%FINAL_DEST%"
echo FINAL_DEST=%FINAL_DEST%
Also, I neglected to slap quotes back on results:
call :CONCAT FINAL_DEST %X3DESTDIR% %X4DESTFIL%
set FINAL_DEST="%FINAL_DEST%"
echo FINAL_DEST=%FINAL_DEST%
After some thought Brian's idea has an advantage also. If only one string has quotes it will work fine. Mine will do nothing.
Better is to have quotes always, than not to have quotes when needed.
Better is to have quotes always, than not to have quotes when needed.
ASKER
thanks to all.
ultimately, stripping out all quotes (including valid and extranneous) and then re-including quotes around any subsequent use of the variable looks like it will do the trick.
ultimately, stripping out all quotes (including valid and extranneous) and then re-including quotes around any subsequent use of the variable looks like it will do the trick.
Regards...