China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 06:55
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Can the delims= in for be a string? View 5,893 Replies 29
Original Poster Posted 2007-05-25 23:42 ·  中国 湖南 娄底 冷水江市 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Can I do this with the for command like this?

@echo off
set "var=333ps555psssword=123 456 789"
for /f "tokens=1* delims=psssword" %%i in ("%var%") do set str=%%i&set num=%%j
echo %str% %num%
pause

My original intention was
Set str=333ps555
num==123 456 789
But the result is
str=333
num=555psssword=123 456 789


Why does the result of my run use p or s as the delimiter instead of psssword?

[ Last edited by 26933062 on 2007-8-13 at 12:13 AM ]
致精致简!
Floor 2 Posted 2007-05-26 00:07 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
delims=psssword
Will use these letters as delimiters; not just p and s, w, o, r, d will also be used as delimiters;

delims cannot be used as delimiters for the string;
Floor 3 Posted 2007-05-26 00:10 ·  中国 湖南 娄底 冷水江市 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Oh. So that's it, it means it can only use a single letter or symbol as a separator, right?

[ Last edited by 26933062 on 2007-8-11 at 05:59 AM ]
致精致简!
Floor 4 Posted 2007-05-26 00:36 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by 26933062 at 2007-5-26 00:10:
Oh. So that's it, it means it can only use a single letter or symbol as a delimiter, right?

This is how the delims option of the for command works.

To use the string "psssword" as a delimiter, I only know that the gawk tool can do it. You can find the download address by searching in the forum.


C:\>echo 333ps555psssword=123 456 789|gawk "BEGIN{FS=\"psssword\"}{str=$1;num=$2;print \"str=\"str\"\nnum=\"num}"
str=333ps555
num==123 456 789
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
sunshine217 +1 2007-06-02 21:24
Floor 5 Posted 2007-05-26 00:40 ·  中国 湖南 娄底 冷水江市 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Oh. Thanks, but I won't use tools,...
Mainly learning batch processing,...
Floor 6 Posted 2007-05-26 00:49 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by 26933062 at 2007-5-26 00:40:
Oh. Thanks. I don't need to use tools,......
Mainly learning batch processing,,,,


Sometimes using some tools can solve many problems, but I don't force it.

Although the delims option of the for command doesn't support string splitting, if you want to achieve your goal, changing the idea might also work:

@echo off
set "var=333ps555psssword=123 456 789"
set "var=%var:psssword=_%"
for /f "tokens=1* delims=_" %%a in ("%var%") do set str=%%a&set num=%%b
echo str=%str%
echo num=%num%
pause
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
nanhui112 +2 2008-03-07 21:39
Floor 7 Posted 2007-06-02 21:25 ·  中国 上海 静安区 电信
新手上路
Credits 0
Posts 1
Joined 2007-06-01 23:13
19-year member
UID 90006
Gender Male
Status Offline
Floor 8 Posted 2007-06-02 21:53 ·  中国 湖南 永州 电信
初级用户
Credits 68
Posts 32
Joined 2006-10-20 12:14
19-year member
UID 67277
Status Offline
Dear all experts, why don't you write comments for the commands? It makes us noobs confused. Some strange characters used in them can't be found online for their usage. As a result, reading them is like not reading. I don't know the specific meaning of each command, and then I can't apply what I've learned to other problems.
Floor 9 Posted 2007-06-04 11:57 ·  中国 四川 绵阳 江油市 电信
高级用户
★★★
Credits 502
Posts 327
Joined 2006-12-30 06:01
19-year member
UID 74981
Gender Male
Status Offline
Originally posted by baikaifang at 2007-6-2 09:53 PM:
Dear experts, why don't you write comments for the commands? It makes us noobs confused. Some strange characters used in them can't be found online. As a result, reading them is like not reading. I don't know the specific meaning of each command, and I can't draw inferences from one instance when encountering other problems. Alas



It's like looking at things through a mist! 3D pictures are seen like that. If you persist in looking for three months, you'll understand. I started looking through a mist last December, and now I can see 3D pictures.
Floor 10 Posted 2007-06-04 15:05 ·  中国 重庆 大足区 联通
初级用户
Credits 44
Posts 25
Joined 2007-03-25 00:24
19-year member
UID 82812
Gender Male
Status Offline
The first part was understood, but the latter part is like天书.
Floor 11 Posted 2007-08-03 08:28 ·  中国 湖北 武汉 电信
新手上路
Credits 9
Posts 5
Joined 2007-08-02 11:01
18-year member
UID 94492
Gender Male
Status Offline
Yeah, it's all like天书.
Floor 12 Posted 2007-08-03 10:12 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
A few seconds for the 3D picture is okay.
Floor 13 Posted 2007-08-08 10:02 ·  中国 广东 湛江 万通宽带网
初级用户
Credits 45
Posts 23
Joined 2007-07-31 11:08
18-year member
UID 94354
Gender Male
Status Offline
Floor 14 Posted 2007-08-16 01:26 ·  中国 陕西 西安 电信
初级用户
Credits 106
Posts 44
Joined 2007-06-01 22:25
19-year member
UID 90001
Gender Male
Status Offline
Moderator lxmxn is really excellent, replacing password with _.
Floor 15 Posted 2007-10-18 22:56 ·  中国 河北 廊坊 联通
初级用户
Credits 36
Posts 14
Joined 2007-03-04 03:22
19-year member
UID 80710
Gender Male
Status Offline
set "var=%var:psssword=_%", replaced password with _.
Learned.
Forum Jump: