Removing & from string
Moderator: DosItHelp
Removing & from string
I used FINDSTR in a FOR loop to pull out a specific string. The string contains an & in it. I am trying to remove it. I tried set q=%q:^&=% and it did not work. Any ideas?
gmh,
Use quotes around the assignment. Btw. it never hurts to use quotes.
DosItHelp?
Use quotes around the assignment. Btw. it never hurts to use quotes.
Code: Select all
set "q=%q:&=%"
DosItHelp?
Did not work...
He is an example of the actual string....
(doc NAME\ &\ NAME2\ NAME3)
If the & was not in the string I have other statements to remove the "(",")", and "\", but with the "&" it messes everything up.
(doc NAME\ &\ NAME2\ NAME3)
If the & was not in the string I have other statements to remove the "(",")", and "\", but with the "&" it messes everything up.
-
- Posts: 36
- Joined: 17 Jul 2008 07:37
Quotes won't help (or hinder) here - you need setlocal enabledelayedexpansion:
Code: Select all
setlocal enabledelayedexpansion
set q=this^&that
echo %q%
set q=!q:^&=or!
echo %q%
Quotes work fine on XP:
Output:
Code: Select all
@echo off
set "q=this&that"
echo."%q%"
set "q=%q:&=%"
echo. %q%
@echo off
set "q=(doc NAME\ &\ NAME2\ NAME3)"
echo."%q%"
set "q=%q:&=%"
set "q=%q:(=%"
set "q=%q:)=%"
set "q=%q:\=%"
echo. %q%
Output:
Code: Select all
"this&that"
thisthat
"(doc NAME\ &\ NAME2\ NAME3)"
doc NAME NAME2 NAME3