| 1. |
Solve : How to prevent variable substitution in SET command? |
|
Answer» I am trying to do the following: you have to use the escape the %, otherwise it thinks you are referring to a veritable That's correct. Quote from: or surround it with %'s That BIT is wrong. Just double the percent signs. Code: [Select]SET I=http://www.someURL.com/My%%20Webpage%%28Version%%20B%%29.htmlinteresting, triple % has ALWAYS worked for me, but maybe only in certain instances.Quote from: Lemonilla on September 05, 2012, 02:32:04 PM interesting, triple % has always worked for me, but maybe only in certain instances. What CIRCUMSTANCES? Quote from: Salmon Trout on September 06, 2012, 01:43:23 PM What circumstances?Everything I've ever WRITTEN, would you LIKE me to post some examples? I'll have to go digging.Quote from: Lemonilla on September 07, 2012, 01:51:18 PM would you like me to post some examples? Yes please. Here, I'll do it for you. Code: [Select]@echo off echo Passed parameters: echo Parameter 1 %1 echo Parameter 2 %2 echo. echo Attempting to escape percent signs in string: echo. echo 1. No escaping SET I=http://www.someURL.com/My%20Webpage%28Version%20B%29.html echo %I% echo. echo 2. Replace one percent sign with two SET I=http://www.someURL.com/My%%20Webpage%%28Version%%20B%%29.html echo %I% echo. echo 3. Replace one percent sign with three SET I=http://www.someURL.com/My%%%20Webpage%%%28Version%%%20B%%%29.html echo %I% echo. echo 4. Replace one percent sign with four SET I=http://www.someURL.com/My%%%%20Webpage%%%%28Version%%%%20B%%%%29.html echo %I% echo. 1. With parameters passed Code: [Select]Passed parameters: Parameter 1 cat Parameter 2 dog Attempting to escape percent signs in string: 1. No escaping http://www.someURL.com/Mydog0Webpagedog8Versiondog0Bdog9.html 2. Replace one percent sign with two http://www.someURL.com/My%20Webpage%28Version%20B%29.html 3. Replace one percent sign with three http://www.someURL.com/My%dog0Webpage%dog8Version%dog0B%dog9.html 4. Replace one percent sign with four http://www.someURL.com/My%%20Webpage%%28Version%%20B%%29.html With no parameters passed Code: [Select]Passed parameters: Parameter 1 Parameter 2 Attempting to escape percent signs in string: 1. No escaping http://www.someURL.com/My0Webpage8Version0B9.html 2. Replace one percent sign with two http://www.someURL.com/My%20Webpage%28Version%20B%29.html 3. Replace one percent sign with three http://www.someURL.com/My%0Webpage%8Version%0B%9.html 4. Replace one percent sign with four http://www.someURL.com/My%%20Webpage%%28Version%%20B%%29.html If you study the above you will see that to get ONE percent sign in the URL string using SET, you need exactly TWO percent signs in the code. Put simply, 2N percents in the code are replaced by N percents in the displayed result, and 2N+1 percents are replaced by N+1 percents. |
|