A trim function
Posted: 21 Oct 2011 13:57
edit:forget this post, there is quite the same function here, sorry I didn't know!
Hi
As I'm using many trim in my batch, I was looking for a good trim function and I tried this:
It seems it works and may be faster than usual trim function, but I'm not sure, what do you think? can this be improved?
And I'm still not very familiar with setlocal command, I don't really undestand where they should be placed in functions
Thx
Hi
As I'm using many trim in my batch, I was looking for a good trim function and I tried this:
Code: Select all
setlocal ENABLEDELAYEDEXPANSION
set "str= some string "
call:trim str
Code: Select all
:trim
call:trim2 %~1 %%%~1%%
goto:eof
:trim2
set tmp_s=%*
for /f "tokens=1* delims= " %%a in ("!tmp_s!") do (set %%a=%%b)
goto:eof
It seems it works and may be faster than usual trim function, but I'm not sure, what do you think? can this be improved?
And I'm still not very familiar with setlocal command, I don't really undestand where they should be placed in functions

Thx