![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-11 18:52 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » What is the difference in usage between tokens=* and delims= in the for command? |
| Printable Version 2,161 / 14 |
| Floor1 oilio | Posted 2007-02-09 09:19 |
| 高级用户 Posts 303 Credits 641 | |
|
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 ] |
|
| Floor2 Climbing | Posted 2007-02-09 21:39 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Just try it yourself.
|
|
| Floor3 lelige | Posted 2007-03-20 23:41 |
| 初级用户 Posts 9 Credits 21 | |
|
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 ] |
|
| Floor4 everest79 | Posted 2007-03-21 00:05 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
| Floor5 9527 | Posted 2007-03-21 01:25 |
| 银牌会员 Posts 438 Credits 1,185 From 北京 | |
|
It can simply give you an example. For example, there is a text a.txt with the following content:
hello world thank you very you are very good These three lines of content for /f "tokens=*" %a in (a.txt) do @echo %a hello world thank you very you are very good It can indirectly delete the spaces in front of each line for /f "delims=" %a in (a.txt) do @echo %a hello world thank you very you are very good Still the original text, heh heh. You can explore the specific parameters and applications inside by yourself |
|
| Floor6 oilio | Posted 2007-03-21 02:16 |
| 高级用户 Posts 303 Credits 641 | |
|
Thank you, brother upstairs. I seem to have grasped a little bit of the essence.
|
|
| Floor7 kgdetg1127 | Posted 2007-10-12 23:10 |
| 初级用户 Posts 89 Credits 158 | |
|
First, top it, and learn slowly
|
|
| Floor8 hxwxyz | Posted 2007-10-13 10:39 |
| 中级用户 Posts 123 Credits 245 | |
|
Learning
|
|
| Floor9 h2thesun | Posted 2008-03-03 23:51 |
| 初级用户 Posts 14 Credits 34 | |
| Floor10 dslz666 | Posted 2008-03-22 17:42 |
| 中级用户 Posts 117 Credits 233 | |
|
After seeing the 3rd floor, I gradually understood, thank you
|
|
| Floor11 Climbing | Posted 2008-03-28 15:50 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
It is suggested to ban the ID of the person upstairs and delete all their posts.
|
|
| Floor12 dosz | Posted 2009-03-07 10:44 |
| 中级用户 Posts 188 Credits 396 From 上海 | |
Originally posted by Climbing at 2007-2-9 21:39: Helping others improve themselves is beneficial to both others and oneself [ Last edited by dosz on 2009-3-7 at 10:51 ] Attachments for命令中 tokens=2 和 delims=, 的用法.PNG (28.5 KiB) |
|
| Floor13 netbenton | Posted 2009-03-07 11:00 |
| 银牌会员 Posts 752 Credits 1,916 From 广西 | |
|
tokens= When the item is empty, only take the first item,
delims= When the item is empty (default), use spaces and [Tab] as delimiters, |
|
| Floor14 prospy | Posted 2009-04-17 23:57 |
| 新手上路 Posts 2 Credits 2 | |
|
Very good, very powerful, I've learned
|
|
| Floor15 welky | Posted 2009-04-24 10:57 |
| 新手上路 Posts 3 Credits 3 | |
|
I've always been unfamiliar with for, but now I'm a bit closer to it!
THANK ALL! |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |