脚本功能是去除字符串前后空格的函数
第一种:
@echo off
set Title= Android 8.x.x 系统工具
call :dels "%Title%" Title
echo #%Title%#
pause
:dels
set abc=%~1
:delleft
if "%abc:~0,1%"==" " set abc=%abc:~1%&&goto delleft
:delright
if "%abc:~-1%"==" " set abc=%abc:~0,-1%&&goto delright
set %~2=%abc%
goto:eof
此种方式要提交两个参数.
第二种:
@echo off
set a= Android 8.x.x 系统工具
call :dels "%a%"
echo #%a%#
pause
:dels
set abc=%~1
:delleft
if "%abc:~0,1%"==" " set abc=%abc:~1%&&goto delleft
:delright
if "%abc:~-1%"==" " set abc=%abc:~0,-1%&&goto delright
for /f "tokens=1,2 delims==" %%i in ('set') do (if "%%j" equ "%~1" set %%i=%abc%)
goto:eof
此种方式提交1个参数即可.作者: newswan 时间: 2018-7-1 14:03
第一种,适用范围大些
可以在被调用函数里:
if %2 == ""
兼容2种情况作者: dos时代菜鸟 时间: 2018-7-1 20:31
:delleft 段结束语句应该 是 exit /b ,而不是 goto :eof 作者: 610644034 时间: 2019-11-8 16:50
for /f "tokens=1,2 delims==" %%i in ('set') do (if "%%j" equ "%~1" set %%i=%abc%) 这是何道理?没有明白作者: 610644034 时间: 2019-11-10 22:08
@echo off
setlocal enabledelayedexpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:去除字符串前后空格
if "" EQU "%~1" goto :eof
set "b_tempstr=%~1"
:去除字符串前后空格_001
if " " EQU "!b_tempstr:~0,1!" set "b_tempstr=!b_tempstr:~1!" && goto :去除字符串前后空格_001
:去除字符串前后空格_002
if " " EQU "!b_tempstr:~-1!" set "b_tempstr=!b_tempstr:~0,-1!" && goto :去除字符串前后空格_002
if "" EQU "%~2" ( for /f "tokens=1,2 delims==" %%i in ('set') do (if "%%j" equ "%~1" set "%%i=!b_tempstr!" & goto :eof))
if "" NEQ "%~2" set "%~2=!b_tempstr!"
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:去除字符串前面空格
if "" EQU "%~1" goto :eof
set "b_tempstr=%~1"
:去除字符串前面空格_001
if " " EQU "!b_tempstr:~0,1!" set "b_tempstr=!b_tempstr:~1!" && goto :去除字符串前面空格_001
if "" EQU "%~2" ( for /f "tokens=1,2 delims==" %%i in ('set') do (if "%%j" equ "%~1" set "%%i=!b_tempstr!" & goto :eof))
if "" NEQ "%~2" set "%~2=!b_tempstr!"
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:去除字符串后面空格
if "" EQU "%~1" goto :eof
set "b_tempstr=%~1"
:去除字符串后面空格_001
if " " EQU "!b_tempstr:~-1!" set "b_tempstr=!b_tempstr:~0,-1!" && goto :去除字符串后面空格_001
if "" EQU "%~2" ( for /f "tokens=1,2 delims==" %%i in ('set') do (if "%%j" equ "%~1" set "%%i=!b_tempstr!" & goto :eof))
if "" NEQ "%~2" set "%~2=!b_tempstr!"
goto :eof