batch file - Control Characters and String Manipulation -
using trick posted on ss64 jeb save backspace control character variable - strange results when 'overlapping' backspaces.
the example in code golfing challenge posted here: backhanded^h^h^h^h^h^hspaces (would appreciate tips code shorter).
ungolfed this:
@echo off setlocal enabledelayedexpansion /f %%a in ('"prompt $h&echo on&for %%b in (1) rem"') set del=%%a set s=%1 echo %s:^h=!del!%
basically, uses jeb's trick save backspace variable, uses string manipulation replace instances of ^h
in input string variable. works correctly following example, , similar inputs:
c:\>bsp.bat "testing^h^h^h test" "test test"
however when 'overlapping' usage of ^h
occurs, following confusing (to me) output:
c:\>bsp.bat "aaa^hb^h^h" "a"b
my question - above example, why receiving output instead of expected "a"
?
i don't understand why "expected output" should "a". see character-by-character output:
bsp.bat "aaa^hb^h^h" " "a "aa "aaa "aaa <- backspace, cursor on last "a" "aab "aab <- backspace, cursor on last "b" "aab <- backspace, cursor on second "a" "a"b
the bs character moves cursor 1 character back. "standard behaviour" of backspace key (also called "backspace echo") "backspace+space+backspace".
by way, method used bs character:
for /f %%a in ('echo prompt $h ^| cmd') set bs=%%a
Comments
Post a Comment