字符串相关的操作,我参看网上的一些文章,如下:
为了完成本次需求,我写了几个函数,完成以下操作
@echo off
set url_str=https://svn.xxxx/svn/E2-resources/defaultroot/file_name.txt
call:getFileName %url_str% file_name
echo %file_name%
call:getParentFolder %url_str% parent_folder
echo %parent_folder%
PAUSE
goto:eof
::---------------------------------------------------------------------
::--get string count target
::---------------------------------------------------------------------
:strCount
set strCount_url_str=%~1
set strCount_length=0
call:strlen %strCount_url_str% strCount_length
set strCount_temp_str=%strCount_url_str:/=%
call:strlen %strCount_temp_str% strCount_temp_str_lenth
set /a %~2=%strCount_length%-%strCount_temp_str_lenth%
goto:eof
::---------------------------------------------------------------------
::--get string length
::---------------------------------------------------------------------
:strlen
set strlen_str=%~1
set strlen_num=0
:next
if not "%strlen_str%"=="" (
set /a strlen_num+=1
set "strlen_str=%strlen_str:~1%"
goto next
)
echo %~1
set "%~2=%strlen_num%"
goto:eof
::---------------------------------------------------------------------
::--get file_name
::---------------------------------------------------------------------
:getFileName
set getFileName_str=%~1
:getFileName_next
if not "%getFileName_str%"=="" (
set "getFileName_str=%getFileName_str:~1%"
if "%getFileName_str:~0,1%"=="/" (
set %~2=%getFileName_str:~1%
)
goto getFileName_next
)
goto:eof
::---------------------------------------------------------------------
::--get file_parent
::---------------------------------------------------------------------
:getParentFolder
set getParentFolder_str=%~1
:getParentFolder_next
if not "%getParentFolder_str%"=="" (
set "getParentFolder_str=%getParentFolder_str:~0,-1%"
if "%getParentFolder_str:~-1%"=="/" (
set %~2=%getParentFolder_str%
goto:eof
)
goto getParentFolder_next
)
goto:eof