批混合特殊字符故障?



据我所知,使用"&quot回显一些特殊字符是可以显示的。我只是停留在代码上,试图找出我可以在哪里改变它的工作。我看不出有什么问题。代码来自这里。我需要的是一个特殊的代码,可以为我写动画,然后退出。就像这样。我从那里复制了代码,修改了它可以用typewriter.bat "text" "charsnum-1"来命名,就像typewriter "Hello" 4一样。虽然我不真的理解批处理混合,而且,即使知道如何解释代码,我也看不出符号在哪里卡住了。

重现我的问题:typewriter.bat "Hello?" 5

代码:

@if (@CodeSection == @Batch) @then
@echo off
setlocal
color 70
set charnuu=%2
call :split chars %1
:begin
for %%i in (%chars%) do call :type "%%~i"
exit /b
goto begin
:split <var_to_set> <str>
setlocal enabledelayedexpansion
set "line="
set "str=%~2"
for /L %%I in (0,1,%charnuu%) do set line=!line! "!str:~%%I,1!"
endlocal & set "%~1=%line%"
goto :EOF
:type <char>
cscript /nologo /e:JScript "%~f0" "%~1"
goto :EOF
@end
// end batch / begin JScript chimera
function pause() { WSH.Sleep(Math.random() * 50 + 50); }
function odds(num) { return !(Math.round(Math.random() * num) % num) }

pause();
if (odds(300)) WSH.Echo('');
if (!odds(400)) WSH.StdOut.Write(WSH.Arguments(0));

此代码不显示常见符号,甚至不显示基本符号,如?。也许我太累了,不想看了。帮助我。

问号不能被常规的for循环处理,但是你可以通过不使用循环处理单个字母而只是将整个字符串作为一个整体进行迭代来解决这个问题:

@echo off
REM Just kinda honor-system the string length since this is proof of concept
REM     but remember that string indices start at 0
set "string=%~1"
set "string_length=%~2"
REM Generate a backspace character for later
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "BS=%%A"
REM The setlocal is down here instead of at the top like it usually is to handle
REM     strings that contain exclamation points.
REM There's a period followed by a backspace before the substring is printed in
REM     case the current character happens to be a space (which otherwise
REM     wouldn't get printed).
REM The timeout /t 0 is because timeout is an external command that technically
REM     needs a few milliseconds to start up, so setting the wait period to 0
REM     seconds actually generates a pause shorter than 1 second.
setlocal enabledelayedexpansion
for /L %%A in (0,1,%string_length%) do (
<nul set /p "=.%BS%!string:~%%A,1!"
>nul timeout /t 0
)

最新更新