is call set similar to subroutine name? what do you use call set LTRIM?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 122
Joined: 26 Aug 2017 06:11

is call set similar to subroutine name? what do you use call set LTRIM?

#1 Post by nnnmmm » 26 Aug 2017 07:02

Code: Select all

SETLOCAL ENABLEDELAYEDEXPANSION
call set "string=%%%~1%%"
set "charlist=%~2"
if not defined charlist set "charlist= "
for /f "tokens=* delims=%charlist%" %%a in ("%string%") do set "string=%%a"
( ENDLOCAL & REM RETURN VALUES
    IF "%~1" NEQ "" SET "%~1=%string%"
)
EXIT /b



this is left trim batch from your website,
i named it as ltrim.bat

then i did ltrim.bat " dddd"
where is the output?

i dont know what call is. it seems like subroutine ltrim (in$, out%)

Code: Select all

in$="   aaa"
call ltrim(in$,out$)
print out$


how can i have this sub effect? with batch call?
Last edited by aGerman on 26 Aug 2017 07:07, edited 1 time in total.
Reason: code tags added

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: is call set similar to subroutine name? what do you use call set LTRIM?

#2 Post by aGerman » 26 Aug 2017 07:30

nnnmmm wrote:then i did ltrim.bat " dddd"
where is the output?

That's not the way it is supposed to work. You really should have read the comments that are prepended to the code.
http://www.dostips.com/DtCodeCmdLib.php#Function.lTrim

So you need a variable with the string. You pass the variable name and the resulting string will be saved in the same variable.

Code: Select all

@echo off
set "mystring=   aaa"
call ltrim.bat mystring
echo %mystring%
pause


Steffen

nnnmmm
Posts: 122
Joined: 26 Aug 2017 06:11

Re: is call set similar to subroutine name? what do you use call set LTRIM?

#3 Post by nnnmmm » 26 Aug 2017 08:45

i am beginning to see how it works, thanks

Post Reply