2014-06-20 47 views
0

我有一個簡單的任務爲一個簡單的子例程,但我可以理解的命令語法與報價和多米諾骨牌引號。批處理:命令來讀取元素列表

在一個批處理文件:

call :mysubroutine "text1;text2;text with spaces;text4" "option1A|option2A;option2B||option with spaces4A;optionwitoutspaces4B" 

我想打印類似:

1: text1 option1A 
2: text2 option2A;option2B 
3: text with spaces 
4: text4 option with spaces4A;optionwithoutspaces4B 

你能幫助我嗎?

+0

這裏有幾十個以前的帖子,演示瞭如何使用for命令和處理引號和解析文本。你有沒有做任何努力來自己做這件事? –

回答

1
@echo off 
setlocal EnableDelayedExpansion 

call :mysubroutine "text1;text2;text with spaces;text4" "option1A| 

option2A;option2B||option with spaces4A;optionwitoutspaces4B" 
goto :EOF 

:mysubroutine 
set "first=%~1" 
set "second=%~2" 
set i=0 
for %%a in ("%first:;=" "%") do (
    set /A i+=1, j=0 
    for %%b in ("%second:|=" "%") do (
     set /A j+=1 
     if !i! equ !j! echo !i!. %%~a %%~b 
    ) 
) 
+0

現在很清楚! :) 謝謝 – CSG