dimanche 19 avril 2015

How to find the position of a character and extract a part of string using batch file

My batch file reads the value of a registry key and stores its value in the variable key. So the value happens to be "H:\KMSpico\KMSpico\Uninst.exe" /u0=KMSpico . I want to extract the part of this string that is enclosed in "". and store it in another variable, say uninstall. I could have easily done it by the following code: SET uninstall=%key:~1,30%. But the problem is that, the part before Uninst.exe, i.e. H:\KMSpico\KMSpico\ which specifies the location of Uninst.exe might change depending upon the location where the user has installed the software, therefore the length of the part that is to be extracted might change. But the above code is set to extract the string only up to 30 characters.


Therefore, I wanted to know if there is way, so that we can somehow know the position of second " , so as to know the number of characters to be extracted. Or if there is some another way, to do this.


Aucun commentaire:

Enregistrer un commentaire