我的批处理脚本需要帮助。我已经成功设置了一个随机数,但是不能用它来得到一个字母,它只使用randnumber一个文本,而我不能使用该值。
setlocal EnableDelayedExpansion
set "string=abcdefghijklmnopqrstuvwxyz"
set /a randnumber=!random! %% 26
set letter=!string:~!randnumber!,1!
查看图片以找出问题所在:Code Syntax Problem
答案 0 :(得分:0)
set letter=!string:~%randnumber%,1!
for %%t in (!randnumber!) do set letterT=!string:~%%t,1!
echo.!letter! !letterT!
答案 1 :(得分:0)
这是我的评论,为您解答。
@Echo Off
Set "String=abcdefghijklmnopqrstuvwxyz"
Set /A Skip=%RANDOM% %% 26
SetLocal EnableDelayedExpansion
Set "Letter=!String:~%Skip%,1!"
Echo %Letter% is the character after skipping the first %Skip%.
Pause
然后call
进行额外的扩展:
@Echo Off
Set "String=abcdefghijklmnopqrstuvwxyz"
Set /A Skip=%RANDOM% %% 26
Call Set "Letter=%%String:~%Skip%,1%%"
Echo %Letter% is the character after skipping the first %Skip%.
Pause