Delete first 3 characters in var in batch file?

How can I do it? I tried:

set /p var="" set var=%var:~3% echo %var% 

For example, if I type โ€œHello Worldโ€, it should repeat โ€œlo Worldโ€.

Sorry, I was too vague. This code is not really code, but it is:

 @echo off setlocal EnableDelayedExpansion set /p file="" set cnt=0 for /F "delims=" %%j in (%file%.txt) do ( set /A cnt+=1 set line!cnt!=%%j ) set cde=0 :code set /a cde+=1 set line=!line%cde%! if %line:~0,9% == err echo.%line:~3% goto code 

I was just trying to make it shorter, still showing an error.

+8
batch-file
source share
1 answer

I just tried it and it works the way you expected. What are you getting?

 C:\>type test.bat set /p var="" set var=%var:~3% echo %var% C:\>test C:\>set /p var="" Hello World C:\>set var=lo World C:\>echo lo World lo World C:\> 

So - it looks like you need two things: 1) Some condition for exiting your second loop. Between the label :code and goto code , when the matching condition is satisfied (i.e. if %line:~0,3% == err ) Without knowing what you need from your code, I would put something like the following

 if %line:~0,3% == err echo.%line:~3% & pause & exit 

This will pause and shut down when a matching string is found.

2) Some exit condition, if you reach the end of the lines, and there was no match. My suspicion is what causes the error you see, since your input file probably does not satisfy this condition.

+7
source share

All Articles