{"id":4429,"date":"2021-11-10T11:12:56","date_gmt":"2021-11-10T11:12:56","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=4429"},"modified":"2021-11-10T11:13:19","modified_gmt":"2021-11-10T11:13:19","slug":"delayed-expansion-and-substring-processing","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/delayed-expansion-and-substring-processing\/27659.html","title":{"rendered":"Delayed Expansion And Substring Processing?"},"content":{"rendered":"<p>Hi,<br \/>\nI&#8217;d like to create variable names where I can control the sort order of the values that the variables contain. I had hoped the following would facilitate such a desire:<\/p>\n<p>&nbsp;<\/p>\n<pre>@ECHO OFF\r\nSETLOCAL ENABLEDELAYEDEXPANSION\r\n\r\nSET \/A position=0\r\nSET order=DEFABC\r\n\r\nFOR \/L %%A IN (1,1,6) DO (\r\n    SET sequence=%order:~!position!,1%\r\n    SET some_variable_!sequence!=%%A\r\n    SET \/A position+=1\r\n)\r\n\r\nFOR \/F \"tokens=1* delims==\" %%A IN ('SET some_variable_') DO (\r\n    ECHO \"%%A\" = \"%%B\"\r\n)\r\n\r\nEXIT \/B\r\n<\/pre>\n<p>Desired output:<\/p>\n<pre>\"some_variable_A\" = \"4\"\r\n\"some_variable_B\" = \"5\"\r\n\"some_variable_C\" = \"6\"\r\n\"some_variable_D\" = \"1\"\r\n\"some_variable_E\" = \"2\"\r\n\"some_variable_F\" = \"3\"\r\n<\/pre>\n<p>Actual output:<\/p>\n<pre>\"some_variable_order:~0,1\" = \"1\"\r\n\"some_variable_order:~1,1\" = \"2\"\r\n\"some_variable_order:~2,1\" = \"3\"\r\n\"some_variable_order:~3,1\" = \"4\"\r\n\"some_variable_order:~4,1\" = \"5\"\r\n\"some_variable_order:~5,1\" = \"6\"\r\n<\/pre>\n<p>What am I missing? You folks here are pretty sharp, and I was curious if there is an alternate method that would accomplish my goal.<\/p>\n<p>*Edit &#8211; Fixed typo<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":2},"question-category":[55],"question_tags":[],"class_list":["post-4429","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/4429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=4429"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=4429"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=4429"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=4429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}