我有一个记事本文件如下:
EID:id
密码:密码
我想读取eid值和密码值,并通过批处理脚本将其粘贴到变量中。我该怎么做呢?
答案 0 :(得分:1)
@echo off
for /f "delims=: tokens=1*" %%G in (a.txt) do set %%G=%%H
set eid=%eid:~1%& set password=%password:~1%
pause
说明:
+------------------------------------------------------------+-------------------+
|Explanation |Result (EID) |
+------------------------------------------------------------+-------------------+
|Line 2: Use a for loop to extract the string after : |" ThisIsYourEidNow"|
+------------------------------------------------------------+-------------------+
|Line 3: Use variable substring to remove the leading space |"ThisIsYourEidNow" |
+------------------------------------------------------------+-------------------+
@echo off
for /f "tokens=2* delims=: " %%p in (textfile.txt) do echo %%p >> tmp.txt
(
set /p "line1="
set /p "line2="
) <tmp.txt
del /f /s /q tmp.txt
pause
脚本执行:
:
之后读取部件(SE显示空间不好)并将其存储到临时文件中答案 1 :(得分:1)
此替代方案不会生成和删除其他文件。
@Echo Off
For /F "UseBackQ Tokens=1* Delims=:" %%A In ("notepad.txt") Do Call :Sub %%A %%B
Set _
Timeout -1
Exit/B
:Sub
Set "_%1=%2"