[我正在尝试从文本文件转换数字-可以说number.txt-从十进制100转换为ASCII 31 30 30。
我可以批量处理吗?
我已经尝试了一些已经在SO上找到的东西-但从来没有正确的输出。
稍后,我将其转换为-我需要在执行某些命令后加一个数字。因此,可以说在109/31 30 39之后-例如应该是110 31 31 30,而不是31 30 3a。
您能给我一个提示吗?
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (nummer.txt) do (
set line=%%a
set a=!line:~0,1!
set line=%%a
set b=!line:~1,1!
set line=%%a
set c=!line:~2,1!
set /a mitte=3!a!3!b!3!c!
echo 0F0900000A00143030303030303030303030303030303030!mitte!00>com3
[请查看下面的Rem
变暗的batch-file示例是否对您有所帮助。
@Echo Off
SetLocal EnableDelayedExpansion
Rem Undefine any existing variable named inputNum.
Set "inputNum="
Rem Read input number from first line of input file.
Set /P "inputNum="<"nummer.txt"
Rem Exit script if inputNum was not defined.
If Not Defined inputNum GoTo :EOF
Rem Define a number of additional iterations [number results required - 1].
Set "#=9"
Rem Define an increment size.
Set "i=5"
Rem Define a variable for total increase, [# x i].
Set /A $=#*i
Rem Undefine an existing verable named arg.
Set "arg="
Rem Begin looping for stated iterations.
For /L %%G In (0,%i%,%$%)Do (
Set /A arg=inputNum+%%G
Rem Call subfunction passing the input number as an argument.
Call :Sub "!arg!"
Rem If successful,
If Defined mitte (
Rem Output resultant number sequence.
Echo !mitte!
) Else (
Rem Exit if no result sequence.
GoTo EndIt
)
)
:EndIt
Rem Allow time to read output before ending.
Pause
EndLocal
GoTo :EOF
:Sub
Rem Undefine any existing variable named mitte.
Set "mitte="
Rem Split each character of passed argument.
For /F Delims^=^ EOL^= %%G In ('"Cmd /U/C Echo(%~1|Find /V """')Do (
Rem prefix each digit of inputNum with 3.
If Not Defined mitte (Set "mitte=3%%G")Else Set "mitte=!mitte!3%%G")
Rem return to next command line after previous Call
Exit /B
对于测试,您只需要确保输入文件路径正确,([line 6
)]。我还提供了一种工具,可以输出固定数量的增量([line 10
)] >>特定数量的其他迭代。请根据需要进行调整。如果12
仅包含nummer.txt
,并且将401
的附加迭代增加9
,应该怎么办:
5
测试后,您可能希望将343031 343036 343131 343136 343231 343236 343331 343336 343431 343436
替换为Echo !mitte!
,([line
] >>(Echo 0F0900000A00143030303030303030303030303030303030!mitte!00)>COM3
)