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-28 19:15
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » [Help] Determining variable length View 1,023 Replies 9
Original Poster Posted 2005-02-25 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
Question for the experts, is there any tool or command that can determine the length of a variable?
For example, set a=chenhui and determine that the length of a is 7
http://www.msfans.net/bbs/
Floor 2 Posted 2005-02-25 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
The strings command should work.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2005-02-25 00:00 ·  中国 上海 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
4DOS has such a function, use 4DOS.
Floor 4 Posted 2005-02-27 00:00 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
You can use Strings.
strings length %a%
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 5 Posted 2005-02-27 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
How do I pass it to a variable?
http://www.msfans.net/bbs/
Floor 6 Posted 2005-02-27 00:00 ·  中国 上海 静安区 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
Floor 7 Posted 2005-02-27 00:00 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
The following is quoted from chenhui530's post at 2005-2-27 10:19:30:

How do I pass it to a variable?


Strings can also pass the output result to a variable. For example: string b=length %a%. Then the result is stored in %b%.
But under Win2000 it seems variables can't be passed in; not sure whether it's a compatibility issue.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 8 Posted 2005-02-27 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
That's exactly what puzzles me, it doesn't work under XP for me either.
http://www.msfans.net/bbs/
Floor 9 Posted 2005-02-28 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
strings does not support setting variables in the NT environment, because under NT the mechanism for creating environment variables is different from 9x and pure DOS, so programs that can work normally under DOS cannot work normally under NT. But it can be worked around completely; of course you need to use lmod@echo off
set a=1234567
strings length %a% | lmod /L1 set L= > temp.bat
call temp.bat
del temp.bat
echo Length is %L%.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 10 Posted 2005-02-28 00:00 ·  中国 上海 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
See, using Microsoft's own command interpreter is such a hassle, you even have to call an external command from disk. In 4DOS, one line solves the problem. Although today's machines are not comparable to the old ones in speed, you still need to have an optimization mindset.
Forum Jump: