2

I was looking to concatenate URL based on keyword given. I passed a variable called "udefine" however, I'm not able to execute the complete concatenated URL. Code provided below.

setlocal EnableDelayedExpansion
set str1="http://myuti.eit.go2uti.com/owd/ITII/_layouts/OSSSearchResults.aspx?k="
set str2=%udefine%
set str3="^&cs=This%%20Site^&u=http%%3A%%2F%%2Fmyuti.eit.go2uti.com%%2Fowd%%2FITII"
set newvar =!%str1%%str2%%str3%!
echo %newvar%

I'm looking to concatenate str1, str2 and str3 as single URL based on input value to str2, the URL should change.

1
  • Thanks Steve Fonton for the edit !! :) Commented Oct 23, 2015 at 22:22

1 Answer 1

1

The command set var =x differs from the set var=x. In the first case you setup the [var ] variable, in the second - [var].

@echo off
setlocal
set "udefine=___"
set "str1=http://myuti.eit.go2uti.com/owd/ITII/_layouts/OSSSearchResults.aspx?k="
set str2=%udefine%
set "str3=&cs=This%%20Site&u=http%%3A%%2F%%2Fmyuti.eit.go2uti.com%%2Fowd%%2FITII"
set "newvar=%str1%%str2%%str3%
echo "%newvar%"
endlocal

Output:

"http://myuti.eit.go2uti.com/owd/ITII/_layouts/OSSSearchResults.aspx?k=___&cs=This%20Site&u=http%3A%2F%2Fmyuti.eit.go2uti.com%2Fowd%2FITII"

You can use set /p str2=Enter udefine: to input a value of str2 from command prompt.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked for me. As suggested, please post your output. Remove the @echo off to see what commands are actually being run.

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.