|
@echo off
setlocal enabledelayedexpansion
set "aaa= 测数 "
::call :去除字符串前后空格 "%aaa%" "aaa"
::call :去除字符串前后空格 "%aaa%"
::call :去除字符串前面空格 "%aaa%"
::call :去除字符串前面空格 "%aaa%" "aaa"
::call :去除字符串后面空格 "%aaa%"
::call :去除字符串后面空格 "%aaa%" "aaa"
echo --!aaa!--
pause
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
:去除字符串前后空格_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 |
|