![]() |
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-17 05:50 |
47,813 topics / 349,903 posts / today 0 new / 48,259 members |
| DOS疑难解答 & 问题讨论 (解答室) » [Help] Determining variable length |
| Printable Version 1,097 / 9 |
| Floor1 chenhui530 | Posted 2005-02-25 00:00 |
| 高级用户 Posts 273 Credits 772 | |
|
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 |
|
| Floor2 Climbing | Posted 2005-02-25 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
The strings command should work.
|
|
| Floor3 DOSforever | Posted 2005-02-25 00:00 |
| 金牌会员 Posts 2,239 Credits 4,639 | |
|
4DOS has such a function, use 4DOS.
|
|
| Floor4 JonePeng | Posted 2005-02-27 00:00 |
| 金牌会员 Posts 1,883 Credits 4,562 From 广东广州 | |
|
You can use Strings.
strings length %a% |
|
| Floor5 chenhui530 | Posted 2005-02-27 00:00 |
| 高级用户 Posts 273 Credits 772 | |
|
How do I pass it to a variable?
|
|
| Floor6 DOSforever | Posted 2005-02-27 00:00 |
| 金牌会员 Posts 2,239 Credits 4,639 | |
| Floor7 JonePeng | Posted 2005-02-27 00:00 |
| 金牌会员 Posts 1,883 Credits 4,562 From 广东广州 | |
The following is quoted from chenhui530's post at 2005-2-27 10:19:30: 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. |
|
| Floor8 chenhui530 | Posted 2005-02-27 00:00 |
| 高级用户 Posts 273 Credits 772 | |
|
That's exactly what puzzles me, it doesn't work under XP for me either.
|
|
| Floor9 Climbing | Posted 2005-02-28 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
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%. |
|
| Floor10 DOSforever | Posted 2005-02-28 00:00 |
| 金牌会员 Posts 2,239 Credits 4,639 | |
|
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.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |