Page 1 of 1

A Value of a space bar is not screened with the Output

Posted: 11 Oct 2015 11:30
by ledlightjungled
To search in the frame of my possibilitys i have some limits with them i can not say have i worked until i can post a question or am i missing something. With the batch file i am writting i am missing something and until now i always had some hints to pinpoint at.
The Output of the batch file is THEWORDIZPAT. But it is not only a set Variable on screen i managed to writte the input to highlight every letter using the space key for every letter screend.
The problem i stumbeled upon is that if a set Variable holds A THEWORDIZPAT in my coding the Output is not as expected A THEWORDIZPAT for every keystroke but ATHEWORDIZPAT. The space form the input vanished at the ouput.

I have to strike the space bar for the space from the input but it is not screened. I hope it is possible to retype the following batch code that i will post and find a clue. Even when there should be no solution something to search for might be useful.

Code: Select all

@echo off
setlocal enabledelayedexpansion
set logic=13
for /l %%a in (1,1,%logic%) do (call :grapefruit %%a)
goto :eof
goto :main

:grapefruit
set count=0
for %%z in (%1) do (
set /a count+=10%%3
set var[!count!]=%%z)

:main
set token=  THEWORDIZPAT
for /f "tokens=* delims=" %%b in ("%token%") do (set word=%%b)
set alien=!word:~%var[1]%,1!
:: for %%y in (%alien%) do (echo|set /p =%%y)
echo|set /p =%alien%
pause > nul
endlocal disabledelayedexpansion


With an additional fullstop alias point in the echo line set /p =.%alien% the space gets visibel but thats all i could manage.
Thanks

Re: A Value of a space bar is not screened with the Output

Posted: 11 Oct 2015 13:29
by Squashman
SET /P strips any white space characters in front of a string. You can test this from the cmd prompt very easily.

Code: Select all

C:\Users\Squash>set /p myvar= no space at beginning
no space at beginning

Re: A Value of a space bar is not screened with the Output

Posted: 11 Oct 2015 13:50
by ShadowThief
You're really close with your idea to use a period to get it to appear. According to this StackOverflow post, leading and trailing spaces are removed from a set prompt, so you need to add in extra characters and then delete them. You can do this by following dbenham's solution of creating a backspace character and adding a period followed by a backspace to all of your characters.

Code: Select all

@echo off
setlocal enabledelayedexpansion
set logic=13
for /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set BS=%%A
for /l %%a in (1,1,%logic%) do (call :grapefruit %%a)
goto :eof
goto :main

:grapefruit
set count=0
for %%z in (%1) do (
set /a count+=10%%3
set var[!count!]=%%z)

:main
set token=A  THEWORDIZPAT
for /f "tokens=* delims=" %%b in ("%token%") do (set word=%%b)
set alien=.%BS%!word:~%var[1]%,1!
:: for %%y in (%alien%) do (echo|set /p =%%y)
echo|set /p =%alien%
pause > nul
endlocal disabledelayedexpansion


And if you want something slightly less verbose, would could also say

Code: Select all

@echo off
setlocal enabledelayedexpansion

for /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set BS=%%A

set "string=A THEWORDIZPAT"
for /L %%A in (0,1,13) do (
   set substring[%%A]=!string:~%%A,1!
   set /p "=.%BS%!substring[%%A]!" <nul
   pause>nul
)

Re: A Value of a space bar is not screened with the Output

Posted: 11 Oct 2015 14:03
by Squashman
You beat me to it ShadowThief. I was looking for the SO post by Dave that did the backspace trick.

Code: Select all

@echo off
setlocal enabledelayedexpansion
set logic=13
for /l %%a in (0,1,%logic%) do (call :grapefruit %%a)
echo.
pause
goto :eof
goto :main

:grapefruit
set count=0
for %%z in (%1) do (
set /a count+=10%%3
set var[!count!]=%%z)

:main

:: Define BS to contain a backspace
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "BS=%%A"

set token=A THEWORDIZPAT
for /f "tokens=* delims=" %%b in ("%token%") do (set "word=%%b")
set "alien=!word:~%1,1!"
:: for %%y in (%alien%) do (echo|set /p =%%y)
echo.|set /p "=.%BS%%alien%"
pause>nul

Re: A Value of a space bar is not screened with the Output

Posted: 11 Oct 2015 14:37
by ledlightjungled
First i read about the prompt $H for /f loop on stackoverflow. I could not link the .%BS% Variable to the Value like it is posted in this post. I linked it to the echo of the %alien% Variable with outher cause.
The iteration with a set Varaiable is new to me and will take some time to manage. So far the posted code works for some further steps.
Thank you for a useful clue to search.

Re: A Value of a space bar is not screened with the Output

Posted: 11 Oct 2015 14:47
by Aacini
You may also generate a backspace character in this slightly simpler way:

Code: Select all

for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"

Antonio

Re: A Value of a space bar is not screened with the Output

Posted: 13 Oct 2015 02:23
by ledlightjungled
The last solution first posted at stackoverflow i come up with is

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f %%A in ('echo prompt $H ^| cmd') do set BS=%%A
set "string=XA THEWORDIZPAT"
for /L %%A in (0,1,14) do (
for /f "tokens=* delims=X" %%b in ("!string:~%%A,1!") do (
set /p=%BS%%%b < nul)
pause > nul
)

Re: A Value of a space bar is not screened with the Output

Posted: 13 Oct 2015 11:19
by ShadowThief
What if your string has more than one X in it?

Re: A Value of a space bar is not screened with the Output

Posted: 15 Oct 2015 01:18
by ledlightjungled
All X added to the set variable are not screend with one letter that matches X used in the delimiter. A second X would be useless. In this case. The delimiter usually for me holds the letters for file extensions.
In a for /f loop without additional bindings the delimiter also can hold more then one letter and all characters at the beginning of the set Variable are substituted. Not like in the posted case on every position, just on the beginning of the echoed Variable.
That´s all i know.