split string
Posted: 23 Feb 2007 01:39
Please fix my error !!!!
REM ~~~~~~~~~~~~
REM count.bat
REM ~~~~~~~~~~~~
@echo off
set info=false
REM default ch=space and str=null
set ch=
set str=
set /a count=0
set /a len=0
if not "%1"=="" set str=%1
if not "%2"=="" set ch=%2
if not "%3"=="" set info=%3
set left=
set right=
:loop
if "%left%"=="%str%" goto end
set left=%str%
set cmd=set left=%%left:~0,%len%%%
call %cmd%
set right=%left%
set cmd=set right=%%right:~-1%%
if not "%left%"=="" call %cmd%
if "%right%"=="%ch%" set /A count=count+1
set /A len=len+1
goto loop
:end
if %info%==true (
echo str=%str%
echo ch=%ch%
echo len=%len%
echo count=%count%
)
REM ~~~~~~~~~~~~
REM split.bat
REM ~~~~~~~~~~~~
@echo off
set str=abc:123:zz:7:8:9
set ch=:
FOR /F "tokens=1,2,3,4,5,6 delims=:" %%i IN ("%str%") DO (
echo. %%i & echo. %%j & echo. %%k & echo. %%l & echo. %%m & echo. %%n
)
call count.bat %str% %ch%
set /a count=count + 1
FOR /L %%c IN (1,1,%count%) DO (
echo %%c
Error here
REM FOR /F "tokens=%c% delims=:" %%i IN ("%str%") DO echo %%i
)
You can copy & paste to create count.bat & split.bat
Then, run split.bat in cmd.
REM ~~~~~~~~~~~~
REM count.bat
REM ~~~~~~~~~~~~
@echo off
set info=false
REM default ch=space and str=null
set ch=
set str=
set /a count=0
set /a len=0
if not "%1"=="" set str=%1
if not "%2"=="" set ch=%2
if not "%3"=="" set info=%3
set left=
set right=
:loop
if "%left%"=="%str%" goto end
set left=%str%
set cmd=set left=%%left:~0,%len%%%
call %cmd%
set right=%left%
set cmd=set right=%%right:~-1%%
if not "%left%"=="" call %cmd%
if "%right%"=="%ch%" set /A count=count+1
set /A len=len+1
goto loop
:end
if %info%==true (
echo str=%str%
echo ch=%ch%
echo len=%len%
echo count=%count%
)
REM ~~~~~~~~~~~~
REM split.bat
REM ~~~~~~~~~~~~
@echo off
set str=abc:123:zz:7:8:9
set ch=:
FOR /F "tokens=1,2,3,4,5,6 delims=:" %%i IN ("%str%") DO (
echo. %%i & echo. %%j & echo. %%k & echo. %%l & echo. %%m & echo. %%n
)
call count.bat %str% %ch%
set /a count=count + 1
FOR /L %%c IN (1,1,%count%) DO (
echo %%c
Error here
REM FOR /F "tokens=%c% delims=:" %%i IN ("%str%") DO echo %%i
)
You can copy & paste to create count.bat & split.bat
Then, run split.bat in cmd.