|
oilio
高级用户
    前进者
积分 641
发帖 303
注册 2007-1-10
状态 离线
|
『楼 主』:
请问for命令中tokens=*和delims=在用法上有什么不同?
使用 LLM 解释/回答一下
用for分析某个文本的内容,为了以防万一文本中用空格分开的行被断掉空格后面的字符串,我看到有的人用"tokens=*"有的人用"delims=" 还有的人两个都用,这两个用法上有什么区别吗?我个人的理解效果应该是一样的吧。
"tokens=*"表示取所有字段,"delims="是指不指定任何分割符,如果文本的第一行有空格断开,用其中一个都可以让分析的字符串不断开吧?是根据各人的爱好两个随便用,还是这两个在用法上有些小技巧?望知道的朋友相告,谢谢您在百忙之中的回帖!<img src="images/smilies/face-wink.png" align="absmiddle" border="0">
Last edited by oilio on 2007-2-8 at 08:51 PM ]
Using for to analyze the content of a certain text. In case the lines separated by spaces in the text are broken and the strings after the spaces are cut off, I see some people use "tokens=*" and some use "delims=", and some people use both. What are the differences in these two usages? I personally understand that the effects should be the same. "tokens=*" means taking all fields, "delims=" means not specifying any delimiter. If there are spaces in the first line of the text to break it, using one of them can make the analyzed string not break, right? Is it that you can use either one according to personal preference, or are there some tips in the usage of these two? I hope the friends who know will tell me, thank you for replying in your busy schedule! ;)
Last edited by oilio on 2007-2-8 at 08:51 PM ]
|

我相信总有一天,总会遇到一个人可以相濡以沫、相吻以湿! |
|
2007-2-9 09:19 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
自己试一下好了。
Just try it yourself.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2007-2-9 21:39 |
|
|
lelige
初级用户
 
积分 21
发帖 9
注册 2005-8-29
状态 离线
|
  『第 3 楼』:
使用 LLM 解释/回答一下
delims是指分割符,tokens是指选取分割后得到的字符串片断。
以下面这段代码为例:
FOR /F "eol=; tokens=2,3* delims=," %i in ("a,bc,def,ghij,jklmn") do @echo %i %j %k
其中Delims是“,”,所以"a,bc,def,ghij,klmn")被分隔成了a bc def ghij klmn这5段。
tokens=2,3* 表示取第2个片段、第3个片段以及第3个片段以后的所有片段,亦即:
%i=bc
%j=def
%k=ghij,klmn(此处“*”表示从第4个片段开始就不用再分割了,统统赋给%k)
所以如果你代码中用“tokens=*”的话,就表示不进行任何分割,直接把当前行赋给循环变量。
Last edited by lelige on 2007-3-20 at 11:42 PM ]
delims refers to the delimiter, and tokens refers to the selected string fragments after splitting.
Take the following code as an example:
FOR /F "eol=; tokens=2,3* delims=," %i in ("a,bc,def,ghij,jklmn") do @echo %i %j %k
Here, Delims is ",", so "a,bc,def,ghij,klmn") is split into 5 segments: a bc def ghij klmn.
tokens=2,3* means to take the 2nd fragment, the 3rd fragment, and all fragments after the 3rd fragment. That is:
%i=bc
%j=def
%k=ghij,klmn (here "*" means that from the 4th fragment onwards, no more splitting is done, all are assigned to %k)
So if you use "tokens=*" in your code, it means no splitting is performed, and the current line is directly assigned to the loop variable.
Last edited by lelige on 2007-3-20 at 11:42 PM ]
此帖被 +3 点积分 点击查看详情 评分人:【 dosjj 】 | 分数: +2 | 时间:2008-11-4 09:25 | 评分人:【 dosz 】 | 分数: +1 | 时间:2009-3-7 09:34 |
|
|
|
2007-3-20 23:41 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
|
2007-3-21 00:05 |
|
|
9527
银牌会员
     努力做坏人
积分 1185
发帖 438
注册 2006-8-28 来自 北京
状态 离线
|
|
2007-3-21 01:25 |
|
|
oilio
高级用户
    前进者
积分 641
发帖 303
注册 2007-1-10
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
谢谢楼上的兄弟,我好像领悟到了一点点精髓。
Thank you, brother upstairs. I seem to have grasped a little bit of the essence.
|

我相信总有一天,总会遇到一个人可以相濡以沫、相吻以湿! |
|
2007-3-21 02:16 |
|
|
kgdetg1127
初级用户
 
积分 158
发帖 89
注册 2007-4-25
状态 离线
|
|
2007-10-12 23:10 |
|
|
hxwxyz
中级用户
  
积分 245
发帖 123
注册 2007-6-8
状态 离线
|
|
2007-10-13 10:39 |
|
|
h2thesun
初级用户
 
积分 34
发帖 14
注册 2007-12-13
状态 离线
|
|
2008-3-3 23:51 |
|
|
dslz666
中级用户
  
积分 233
发帖 117
注册 2007-11-28
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
看了3楼的渐渐地明白了,,谢谢
After seeing the 3rd floor, I gradually understood, thank you
|
|
2008-3-22 17:42 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
建议把楼上这个人的ID封掉同时删除其所有发帖。
It is suggested to ban the ID of the person upstairs and delete all their posts.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2008-3-28 15:50 |
|
|
dosz
中级用户
   一看二跟三动手
积分 396
发帖 188
注册 2005-10-23 来自 上海
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by Climbing at 2007-2-9 21:39:
自己试一下好了。
帮助别人提高自己于人于已都有利
@echo off
title for命令中 "tokens=2 和 delims=," 的用法
echo.
echo 床前明月光,疑是地上霜,举头望明月,低头思故乡
echo.
echo 如果我要用for将四句诗都显示到屏幕上,不需要任何参数即能实现:
echo for /f %%i in (静夜思.txt) do echo %%i
ECHO 1-1床前明月光,1-2疑是地上霜,1-3举头望明月,1-4低头思故乡。> 静夜思.txt
ECHO 2-1床前明月光,2-2疑是地上霜,2-3举头望明月,2-4低头思故乡。>>静夜思.txt
ECHO 3-1床前明月光,3-2疑是地上霜,3-3举头望明月,3-4低头思故乡。>>静夜思.txt
for /f %%i in (静夜思.txt) do echo %%i
pause>nul
echo.
ECHO 如果我只要“床前明月光”这句话,就需要delims帮忙了:
ECHO for /f "delims=," %%i in (静夜思.txt) do echo %%i
for /f "delims=," %%i in (静夜思.txt) do echo %%i
ECHO delims=后面跟了一个逗号,表示用原文中的逗号作为分隔符(划分的方法)将古诗分成四个小节。默认情况下,delims只显示分隔符前的第一小节,分隔符通常被忽略掉。
pause>nul
echo.
ECHO 显示其他小节的诗句要用到列提取命令“tokens”。
ECHO for /f "tokens=2 delims=," %%i in (静夜思.txt) do echo %%i
for /f "tokens=2 delims=," %%i in (静夜思.txt) do echo %%i
ECHO tokens=2 表示对象(在这里是每行)的第2个字符集
pause>nul
Last edited by dosz on 2009-3-7 at 10:51 ]
Originally posted by Climbing at 2007-2-9 21:39:
Just try it yourself.
Helping others improve themselves is beneficial to both others and oneself
@echo off
title Usage of "tokens=2 and delims=," in the for command
echo.
echo Before the bed the bright moon shines, I think frost on the ground it is. Raising my head, I watch the bright moon, lowering my head, I think of home.
echo.
echo If I want to display all four lines of the poem on the screen using for without any parameters, it can be achieved:
echo for /f %%i in (JingYeSi.txt) do echo %%i
ECHO 1-1 Before the bed the bright moon shines, 1-2 I think frost on the ground it is, 1-3 Raising my head, I watch the bright moon, 1-4 Lowering my head, I think of home.> JingYeSi.txt
ECHO 2-1 Before the bed the bright moon shines, 2-2 I think frost on the ground it is, 2-3 Raising my head, I watch the bright moon, 2-4 Lowering my head, I think of home.>>JingYeSi.txt
ECHO 3-1 Before the bed the bright moon shines, 3-2 I think frost on the ground it is, 3-3 Raising my head, I watch the bright moon, 3-4 Lowering my head, I think of home.>>JingYeSi.txt
for /f %%i in (JingYeSi.txt) do echo %%i
pause>nul
echo.
ECHO If I only want the sentence "Before the bed the bright moon shines", I need the help of delims:
ECHO for /f "delims=," %%i in (JingYeSi.txt) do echo %%i
for /f "delims=," %%i in (JingYeSi.txt) do echo %%i
ECHO delims= followed by a comma means using the comma in the original text as the delimiter (the method of division) to divide the ancient poem into four sections. By default, delims only displays the first section before the delimiter, and the delimiter is usually ignored.
pause>nul
echo.
ECHO To display the verses of other sections, the column extraction command "tokens" is used.
ECHO for /f "tokens=2 delims=," %%i in (JingYeSi.txt) do echo %%i
for /f "tokens=2 delims=," %%i in (JingYeSi.txt) do echo %%i
ECHO tokens=2 means the second character set of the object (here, each line)
pause>nul
Last edited by dosz on 2009-3-7 at 10:51 ]
附件
1: for命令中 tokens=2 和 delims=, 的用法.PNG (2009-3-7 10:44, 28.5 KiB,下载次数: 3)
|

*/. . . * .
.\* . * dosz
*/ . ./\~~~~~~~~~~~~'\. ^|◆
\* ,/,..,\,...........,\.◆
^|^| ..▎# ▎田 田 ▎ ^| ▎◆
^|^| ^&^&▎ ▎ ▎'^|'▎ o
^|^| ##■■■■■■■■■■〓 |
|
2009-3-7 10:44 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
tokens=项为空时只取第一项,
delims=项为空时(默认)以空格及[Tab]为分隔,
tokens= When the item is empty, only take the first item,
delims= When the item is empty (default), use spaces and as delimiters,
|

精简
=> 个人 网志  |
|
2009-3-7 11:00 |
|
|
prospy
新手上路

积分 2
发帖 2
注册 2009-4-13
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
很好很强大,学习了
Very good, very powerful, I've learned
|
|
2009-4-17 23:57 |
|
|
welky
新手上路

积分 3
发帖 3
注册 2009-4-21
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
一直对for感到陌生,现在有和他亲近了点!
THANK ALL!
I've always been unfamiliar with for, but now I'm a bit closer to it!
THANK ALL!
|
|
2009-4-24 10:57 |
|