我需要在第一行读取并确定它是空白还是数字串。如果是空行,程序将告诉该文本无效然后终止,否则我将使用该字符串进行进一步计算。 但是,我使用的代码如下,它只是不能存储空白行,以便我不能使用if语句来检查它是否为空或“”。有什么建议吗?
set "text_file=20150629_eleave_i_test.txt"
:: Get the first six characters of the first line
set /p first_six=<%text_file%
如果记事本++视图中的文本文件是
1
2 00000720150625
感谢您提前。
答案 0 :(得分:3)
这应该有效:
set "text_file=20150629_eleave_i_test.txt"
set "first_line="
set /p first_line=< %text_file%
if not defined first_line (
echo This text is invalid
goto :EOF
)
set "first_six=%first_line:~0,6%"
答案 1 :(得分:2)
@echo off
setlocal enableDelayedExpansion
set "ln="
set /p "ln=" <"20150629_eleave_i_test.txt"
if not defined ln (
echo First line is empty
) else (
for /f "delims=0123456789" %%A in ("%ln%") do echo First line is not fully numeric
) || echo First line is fully numeric