简体   繁体   English

For / f中的delims选项可以是字符串吗?

[英]Can option of delims in For / f be a string?

My code is as follows: 我的代码如下:

for /F "tokens=1,2 delims=%0.3%" %%i in ("double a = 0.3;") do ( 对于/ F“ tokens = 1,2 delims =%0.3%” %% i in(“ double a = 0.3;”)执行(

set a=%%i 设置a = %% i

set b=%%j 设置b = %% j

)

I want a = "double a = " and b =";" 我想要一个=“ double a =”和b =“;” but this code can not help. 但是这段代码无济于事。

Does anyone know how to solve this problem? 有谁知道如何解决这个问题?

Your code as posted simply will not work at all. 您发布的代码根本无法使用。

for /F "tokens=1,2 delims=%0.3%" %%i in ("double a = 0.3;") do (

The %0 will be replaced by yourbatchfilename and since %" % has no value set in the environment, it will be replaced by [nothing] yielding %0将由yourbatchfilename替换,并且由于%" %在环境中未设置值,它将由[nothing]替换

for /F "tokens=1,2 delims=yourbatchfilename.3i in ("double a = 0.3;") do (

which, unsurprisingly, is a syntax error. 毫不奇怪,这是语法错误。

@ECHO OFF
SETLOCAL
for /F "tokens=1,2 delims=3.0" %%i in ("double a = 0.3;") do (
set a=%%i
set b=%%j
)
ECHO first way  :a=%a%+ b=%b%+

ENDLOCAL
SETLOCAL
SET "astring=double a = 0.3;"
SET "aseparator=0.3"
SET "arotorapes=3.0"
for /F "tokens=1,2 delims=%arotorapes%" %%i in ("double a = 0.3;") do (
SET a=%%i
)
CALL SET b=%%astring:*%aseparator%=%%

ECHO second way :a=%a%+ b=%b%+

ENDLOCAL
SETLOCAL
SET "astring=double a = 0.3;"
SET "aseparator=0.3"
CALL SET b=%%astring:*%aseparator%=%%
SET "c=%b%%aseparator%"
SET "a=%astring%"
:loop
IF DEFINED c SET c=%c:~0,-1%&SET a=%a:~0,-1%&GOTO loop

ECHO third way  :a=%a%+ b=%b%+

In the first method, I've changed the sequence of the characters to deomstrate that any sequence of any of the characters between the = and " of a delims clause acts as a SINGLE delimiter. The code "works" by failing to fail. 在第一种方法中,我更改了字符的顺序以消除delims子句的="之间的任何字符的任何序列都充当单个定界符。代码“工作”失败了。

In the second method, the setting of a works in the same way. 在第二种方法中,设置a以相同的方式工作。 Without further information, it's really not possible to tell whether this is adequate. 没有更多的信息,实际上就无法确定这是否足够。 b is set by specifically replacing all characters in the source string up to and including the separator with [nothing] 通过专门用[nothing]替换源字符串中的所有字符,直到并包括分隔符,来设置b

In the third method, the same operation establishes b , and then b and the separator are concatenated. 在第三种方法中,相同的操作建立b ,然后将b和分隔符连接起来。 Systematically lop off the characters at the end of a copy of the original original string and the concatenated string. 系统地删除原始原始字符串和串联字符串副本末尾的字符。 When the concatenated version becomes empty, you've deleted the separator and the appendix from the original, leaving the portion of the original string up to the separator. 当串联的版本变为空时,您已从原始副本中删除了分隔符和附录,而将原始字符串的一部分留给了分隔符。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在java中使用运行命令选项设置字符串变量? - How i can set a string variable with a run command option in java? 用bat在字符串位置查找最后一位的最佳选择 - Best option to find last digits in a position of string with bat 在 Laravel 中,如何将多维数组作为 artisan 命令的选项传递? - In laravel, how can i pass a multidimensional array as an option for artisan command? 如何使用引号和正则表达式 grep aa 字符串? - How can I grep a a string with quotes and a regex? 您能告诉我一个快速工作的片段来解决此命令行选项的情况吗? - Can you show me a quick working snippet to solve this command line option case? 如何在 Visual Studio C++ 项目中删除单个文件的命令行选项? - How can I remove command line option for single file in the visual studio c++ project? tail -f始终显示“已杀死” - tail -f always displays “Killed” 如何修复尝试安装 pythonnet 的命令行错误“错误:选项 --single-version-externally-managed-not-recognized”? - How can I fix command line error "error: option --single-version-externally-managed-not-recognized" trying to install pythonnet? 如何使用awk验证HTT,并输出字符串作为结果? - How can you use awk to verify HTT, and output a string as the result? 我可以在bash / fishshell中使用任何字符串操作命令/库吗? - Is there any string manipulation commands/libraries I can use in bash/fishshell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM