Windows Batch循环虽然带有动态令牌计数的变量
发布时间:2020-12-13 23:27:09 所属栏目:Windows 来源:网络整理
导读:在我的 Windows批处理文件中,我有一些带有不同数量字符串的变量. 为了exapmle: set string="-start" "-end someOption" 我用以下方式计算String的数量: Set count=0For %%j in (%string%) Do Set /A count+=1echo.Total count: %count% 输出将是: Total c
在我的
Windows批处理文件中,我有一些带有不同数量字符串的变量.
为了exapmle: set string="-start" "-end someOption" 我用以下方式计算String的数量: Set count=0 For %%j in (%string%) Do Set /A count+=1 echo.Total count: %count% 输出将是: Total count: 2 现在我想在我的变量中使用Strings多次启动一个应用程序,我想给应用程序提供当前字符串作为参数.我试过这个: FOR /L %%H IN (1,1,%COUNT%) DO ( echo %%H FOR /F "tokens=%%H " %%I IN ("%string%") Do ( echo %%I rem java -jar app.jar %%I ) ) 但不幸的是,这不起作用:这是输出:
如何在变量“string”中循环遍历两个字符串?
您不能在FOR / F的选项字段中使用FOR参数或延迟扩展变量.
但是你可以创建一个函数并使用百分比扩展. 拆分是delim字符的效果,它是默认空间和制表符,它们也适用于带引号的参数. set string="-start";"-end someOption" set count=0 For %%j in (%string%) Do Set /A count+=1 echo.Total count: %count% FOR /L %%H IN (1,%COUNT%) DO ( echo %%H call :myFunc %%H ) exit /b :myFunc FOR /F "tokens=%1 delims=;" %%I IN ("%string%") Do ( echo %%~I rem java -jar app.jar %%I ) exit /b (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 如何检查Windows shell中是否有命令?
- 远程桌面报错解决:No Remote Desktop License Servers Ava
- xaml – Windows Phone 8的默认控制模板
- wcf – Azure AppFabric和Windows Server AppFabric有什么区
- 在Windows上存储python应用程序的配置文件的位置
- .net – 复制本地和系统dll’ – 重点是什么?
- .net – Windows WPF或Silverlight中的VT100终端仿真
- 虚拟机上的Windows 7
- windows-server-2008-r2 – 为什么Window的SSL Cipher-Suit
- win10激活错误,软件授权服务报告无法激活计算机怎么办?
推荐文章
站长推荐
热点阅读