中国DOS联盟论坛

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-10-02 01:54
47,813 topics / 349,918 posts / today 0 new / 48,279 members
DOS批处理 & 脚本技术(批处理室) » Please help optimize and modify this?
Printable Version  1,135 / 1
Floor1 guo882633 Posted 2010-04-01 22:23
初级用户 Posts 53 Credits 126 From -
@echo off
mode con lines=20 cols=90

:sot
cls
echo.
set ID=
set /p ID= Please enter the 3-digit student code:
for /f "tokens=1*" %%i in ('findstr "%ID:~0,10%" mdb.txt') do (
cls
echo.
echo Student ID: %ID%
echo.
echo.
echo Student information: %%j
)
pause >nul 2>nul
goto sot

Contents of mdb.txt
00001 Zhang San Chinese Score: 100 points
00002 Zhang Si Chinese Score: 85 points
00003 Zhang Wu Chinese Score: 90 points

Please ask an expert to help modify this so the results are displayed on separate lines (for example: name on one line, subject on one line, score on one line)
Thanks
Floor2 Hanyeguxing Posted 2010-04-02 13:07
银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂
'findstr "%ID:~0,10%" mdb.txt' is wrong when used like this. For example, when ID is 1, findstr cannot distinguish between 00001 and 00011 and things like 成绩:100分.

This allows ID values like 1 or 01 or 001 or 0001 or 00001, all equivalent to 00001
The variable %m% is the maximum value of the student ID
It is recommended that the IDs in mdb.txt be consecutive numbers starting from 00001
If the entered ID exactly matches the one in mdb.txt, then the part from :n to ::query can be omitted

[ Last edited by Hanyeguxing on 2010-4-2 at 14:52 ]
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023