![]() |
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-09 06:23 |
47,811 topics / 349,895 posts / today 0 new / 48,253 members |
| DOS批处理 & 脚本技术(批处理室) » [Original] A New Method for Calculating String Length |
| Printable Version 1,896 / 10 |
| Floor1 quya | Posted 2008-07-11 11:52 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
|
I'm no good at anything else, but sometimes I get sudden ideas.
Please test the following code, so as to inspire everyone to dig into the potential of certain commands. |
|
| Floor2 slore | Posted 2008-07-11 12:26 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
What you get is not the string length, but... the byte count...
If it's Chinese characters... PS: If you're using the file size method, it seems you can use for's %~zI |
|
| Floor3 HAT | Posted 2008-07-11 13:14 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Can't really count as a new method, right? People brought up the offset method a long time ago.
|
|
| Floor4 zh159 | Posted 2008-07-11 14:16 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
If you're generating a temporary file, then just use for's %~zI directly, otherwise use the method from post #3
|
|
| Floor5 HAT | Posted 2008-07-11 15:00 |
| 版主 Posts 5,017 Credits 9,023 | |
|
If you also calculate Chinese characters by offset, you'll get the wrong result, hehe.
|
|
| Floor6 quya | Posted 2008-07-11 18:35 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
|
But I did think of this independently. I didn't know someone had already brought it up. What a pity, I originally thought it was the first of its kind.
If I'd known earlier, I wouldn't have taken it out and made a fool of myself. By the way, can anyone give some detailed examples of findstr? List each parameter, especially things in regular expressions like $ and \X and the like. I really haven't seen any concrete examples. |
|
| Floor7 pusofalse | Posted 2008-07-11 18:38 |
| 银牌会员 Posts 646 Credits 1,604 | |
|
TO 6
This is the FINDSTR usage info I collected. It's very helpful, let's learn it together!~ |
|
| Floor8 HAT | Posted 2008-07-11 19:10 |
| 版主 Posts 5,017 Credits 9,023 | |
|
For reference on the function of symbols in CMD/DOS
http://www.cn-dos.net/forum/viewthread.php?tid=30985&fpage=4 If you still don't understand, you can post the findstr command you saw, and naturally someone will explain it, hehe. |
|
| Floor9 whitegod | Posted 2008-07-12 11:04 |
| 初级用户 Posts 13 Credits 26 From 江苏无锡 | |
|
OP, I just looked at your program for calculating character length, and there's a question: why do you subtract 4 at the end, and not 3? eof is only three characters. Thanks for clearing that up for me.
|
|
| Floor10 HAT | Posted 2008-07-12 11:20 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Subtract 4, namely: two double quotation marks, one newline character \n, and one text end marker eof
|
|
| Floor11 whitegod | Posted 2008-07-12 11:33 |
| 初级用户 Posts 13 Credits 26 From 江苏无锡 | |
|
Thanks, brother above
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |