cann't pass variable into string function

July 14, 2011 at 03:39:31
Specs: Windows XP
Hello Team.

set str=test123
set length=3
set str = %str:~0,-!length!%
echo %str%

Iam getting output str:~0,3 instead of test. I cannot put the number 3 directly. Please help.


See More: cannt pass variable into string function

Report •

#1
July 14, 2011 at 12:15:11
@echo off
SetLocal EnableDelayedExpansion
set str=test123
set length=4

for /L %%a in (%length%,%length%,%length%) do (
set str=!str:~0,%%a!
)
echo %str%


Report •

#2
July 14, 2011 at 23:45:01
@dtech10

Why not just:

SetLocal EnableDelayedExpansion
set str=test123
set length=4

set str=!str:~0,-%length%!
echo %str%


Report •

#3
July 15, 2011 at 13:13:53
Hi Judado

Youre right, my brain must have been working overtime.
Maybe too much beer the night before.


Report •
Related Solutions


Ask Question