getSubStr

getSubStr.bat源码
@echo off
set %0~string=%string%
set %0~position=%position%
set %0~count=%count%
set %0~result=
set string=%1
set /a position=%2
set /a count=0
set string=%string:"=%
if %position% LSS 0 (
for %%i in (%string%) do (
set /a count=!count!+1
)
set /a position=%position%+!count!
)
set /a count=0
for %%i in (%string%) do (
if !count! EQU %position% (
set %0~result=%%i
set /a count=!count!+1
)
set string=!%0~string!
set position=!%0~position!
set count=!%0~count!
使用实例1:
@echo off
Setlocal enabledelayedexpansion
set path=%path%;%cd%\lib
call getSubStr "a,b,c,d" 0
set result=!getSubStr~result!
echo the first subString is %result%
call getSubStr "a;b;c;d" 1
set result=!getSubStr~result!
echo the second subString is %result%
call getSubStr "a b c d" -1
set result=!getSubStr~result!
echo the firest subString from right is %result%
pause

你可能感兴趣的:(c,String,Path)