To re-iterate my comment, the following does not know or count the substring length, it simply removes the first two and last two characters from the string:
Set "String=AB134SSPQS"
Set "subString=%String:~2,-2%"
Echo %subString%
If AB
and QS
precede and succeed the required substring but do not necessarily begin and start the string, then perhaps this will work for you:
Rem Looking for a file.txt substring preceded by AB and succeeded by QS
@Echo Off
For /F "Delims=" %%A In ('FindStr /I "AB.*QS" "file.txt"') Do Call :Sub "%%A"
Pause
GoTo :EOF
:Sub
Set "Line=%~1"
Set "Up2Sub=%Line:*AB=%"
Set "SubStr=%Up2Sub:QS="&:"%"
Echo %SubStr%
Exit /B
I've had to make up a scenario, (see Rem
), because you've not provided sufficient information on which to base an answer.
Edit
Set "String=AB134SSPQS"
Set "Up2Sub=%String:*AB=%"
Set "SubStr=%Up2Sub:QS="&:"%"
Echo %SubStr%
Edit2
As given in your other question, and added here based on your now changed question, here's one method:
@Echo Off
Set "CMS_SQL=cms91_to_913.json cms913_to_9132.json cms9132_to_9133.json cms9133_to_10100.json"
Set "CMS_FROM_VERSION=cms913_"
Set "CMS_TO_VERSION=to_9133.json"
For /F "Delims=" %%A In ('Echo %%CMS_SQL:*%CMS_FROM_VERSION%^=%%'
) Do Set "SUBSTRING=%CMS_FROM_VERSION%%%A"
For /F "Delims=" %%A In ('Echo %%SUBSTRING:%CMS_TO_VERSION%^=^&:%%'
) Do Set "SUBSTRING=%%A%CMS_TO_VERSION%"
Set SUBSTRING
Pause