Home > Back-end >  What does the following piece of cmd code means?
What does the following piece of cmd code means?

Time:12-18

What does this piece of code means? Could someone explain it to me?


set "txt=!txt:~0,-1!"

@echo off
setlocal EnableDelayedExpansion
set "txt="
set input=input.txt
for /f "delims=" %%a in (%input%) do (
  set "txt=!txt!%%a,"
)
set "txt=!txt:~0,-1!"
>new.txt echo !txt!

CodePudding user response:

This code returns a substring of the contents of the variable txt. The two numbers indicate the start and end location of the requested substring in the original value of variable txt. A negative value for the second number means count backwards. So in your example the returned value will be the contents of variable txt without the last character. For more info on this syntax see: https://ss64.com/nt/syntax-substring.html

CodePudding user response:

It does mean: 'cut last character from variable !txt!'

  • Related