批量混合特殊字符错误?
Batch-Hybrid Special Character Fault?
据我所知,有些特殊字符用""回显是可以显示的。我只是停留在代码上,试图找出可以更改的位置以使其正常工作。我看不出问题所在。来自 here 的代码。
我需要的是一个特殊的代码,可以为我编写动画,然后退出。就这样。我从 there 复制了代码,对其进行了修改,以便可以使用 typewriter.bat "text" "charsnum-1"
调用它,例如 typewriter "Hello" 4
。虽然我真的不了解 Batch Hybrids,而且即使知道如何解释代码,我也看不出符号卡在哪里。
重现我的问题: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
)
据我所知,有些特殊字符用""回显是可以显示的。我只是停留在代码上,试图找出可以更改的位置以使其正常工作。我看不出问题所在。来自 here 的代码。
我需要的是一个特殊的代码,可以为我编写动画,然后退出。就这样。我从 there 复制了代码,对其进行了修改,以便可以使用 typewriter.bat "text" "charsnum-1"
调用它,例如 typewriter "Hello" 4
。虽然我真的不了解 Batch Hybrids,而且即使知道如何解释代码,我也看不出符号卡在哪里。
重现我的问题: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
)