You must first understand that these commands:
set a=a set b=b set c=c
... are "by definition" useless (that is, without any further explanation), although it should be obvious that in this case the spelling of %a% will always be the same as spelling only a (the same will happen for the rest of the letters) .
If you want to change one letter to a string of numbers, then the correct path should be as follows:
set a=543241254 set b=785214185 set c=842501445
Then, to change the letter "a" to the contents of the variable, you can do something like this in your for command:
set "line=!line:a=%a%!"
Again: this will change the letter a to the contents of the variable a .
Now you should understand that you need to perform the previous replacement not by a single letter / variable a , but by a number of variables represented by each one letter. The standard way to handle a sequence of variables in the same way (which actually means “using the same code”) is the for command, which changes the index value in combination with array . For example, if we select the letter “name” for the name of the array and determine the required replacement values in different elements of the array, we will do something like this:
set letter[a]=543241254 set letter[b]=785214185 set letter[c]=842501445
After that, we just need to know how to manipulate these variables / values. Full details on this are given in arrays, linked lists, and other data structures in the cmd.exe (batch) script , so I won’t repeat them here again. However, managing the array needed to solve this problem is simpler than the full explanation given in this link.
If you run this command: set letter , all variables starting with a letter will be displayed, including their values; eg:
letter[a]=543241254 letter[b]=785214185 letter[c]=842501445
If we use the for /F "tokens=2,3 delims=[]=" %%a in ('set letter') do ... command for /F "tokens=2,3 delims=[]=" %%a in ('set letter') do ... , then the replaceable parameter %%a will contain each of the array indices, that is, the letters a , b , c etc. and the %%b parameter will contain the corresponding numeric values.
Thus, to complete your program and replace all the specific letters, you just need to put your line set "line=!line:%b%=%bb%!" into the previous for command and correctly change the part of %b% representing the letter to %%a ; and replace the %bb% part that represents the numeric value with %%b :
for /F "tokens=2,3 delims=[]=" %%a in ('set letter') do ( set "line=!line:%%a=%%b!" )
Of course, you should also define a letter array at the beginning of the program ...