1

I am trying to loop through a list of URL's and keep running into trouble. Specifically, I keet running into trouble with parameters, because of the equals sign.

set  loadval[1]="/orders/counts"
set  loadval[2]="/orders/counts?aggregationKind=Day&fullHistory=true"
set  loadval[3]="/products/popularity?aggregationKind=Month&aggregationCount=12"
set  loadval[4]="/products/popularity/aggregated?aggregationKind=Month&aggregationCount=12"

for /F "tokens=4 delims==" %%s in ('set loadval[') do (
  echo    Connecting to %%s
)

Ideas?

2 Answers 2

4

Your tokens=4 value is wrong. In set loadval[ command, the displayed values are similar to these ones:

loadval[1]="/orders/counts"
loadval[2]="/orders/counts?aggregationKind=Day&fullHistory=true"
loadval[3]="/products/popularity?aggregationKind=Month&aggregationCount=12"
loadval[4]="/products/popularity/aggregated?aggregationKind=Month&aggregationCount=12"

If you want to process the value after the equal sign, then it is the token after the first one separated by =:

for /F "tokens=1* delims==" %%s in ('set loadval[') do (
  echo    Connecting to %%t
)
Sign up to request clarification or add additional context in comments.

3 Comments

You are correct, I didn't clean up my question code back to its original version, which is what you are suggesting. Unfortunately, using the tokens method wont' work with several of the URLs listed above because of the equals signs within them. This is why I started trying to find another solution, which resulted in the solution I posted.
All equals signs after the first one will be properly preserved, when using 1* and Aacini is correct.
Ok, I see what you are talking about. This is a better solution than the one that I posted. Thanks
0

Here is what I did:

setlocal enabledelayedexpansion

set  loadval[1]="/orders/counts"
set  loadval[2]="/orders/counts?aggregationKind=Day&fullHistory=true"
set  loadval[3]="/products/popularity?aggregationKind=Month&aggregationCount=12"
set  loadval[4]="/products/popularity/aggregated?aggregationKind=Month&aggregationCount=12"

for /L %%a in (1,1,4) do (
  call echo     Connecting to !loadval[%%a]!
)

Hope this helps someone else out there.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.