Page 1 of 1

ampersand problem find in a row

Posted: 12 Aug 2010 04:13
by darioit
Hello again,

this batch really works well, but when in a row there's some "&" ampersand simbol, this is interpreted as a command and divide the outpur result in two line also I got this errors sometimes

Numero non valido. Le costanti numeriche sono decimali (17),
esadecimali (0x11) o ottali (021).
"sleep" non รจ riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.
Numero non valido. Le costanti numeriche sono decimali (17),
esadecimali (0x11) o ottali (021).


I try to use "%name%" and works fine, but I don't want "" in a new file

Any idea? Thanks in advance
Best

Code: Select all

@echo off &setlocal
pushd "E:\bat\Temp"

for /f "delims=" %%a in (fileinput.txt) do set "name=%%a"&call :procName

popd
goto :eof

:procName
if "%name:~2,2%"=="00" (
  for /f "usebackq tokens=1,2 delims=;" %%a in ("%~dp0Table2.txt") do if "%name:~4,4%"=="%%a" (
    set "newCode1=%%b"
    for /f "usebackq tokens=1,2 delims=;" %%c in ("%~dp0Table1.txt") do if "%name:~0,2%"=="%%c" (
      set "newCode2=%%d"
      goto break_loop
    )
  )
)

:break_loop
>> "ADDRESS.%newCode1%.%newCode2%" ECHO %name%
goto :eof

Re: ampersand problem find in a row

Posted: 12 Aug 2010 07:19
by aGerman
Escape it this way:

Code: Select all

:break_loop
set "name=%name:&=^&%"
>> "ADDRESS.%newCode1%.%newCode2%" ECHO %name%
goto :eof


Regards
aGerman

Re: ampersand problem find in a row

Posted: 12 Aug 2010 08:04
by darioit
Thanks aGerman, you're the best, but why the suggestion on this site doesn't work?

http://www.dostips.com/DtTipsStringOper ... veBothEnds
and also this
http://www.dostips.com/DtTipsStringOper ... TrimQuotes

Thanks
Dario

Re: ampersand problem find in a row

Posted: 12 Aug 2010 08:14
by aGerman
Hmm, works for me. In case you have special characters like &<>| in the variable value it will probably not work. Tell me an example where it doesn't work for you.

Regards
aGerman