Padding with blanks...

  • Thread starter mathewsdw@sbcglobal.net
  • Start date
  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
M

mathewsdw@sbcglobal.net

Guest
#1
Here's a really simple (really! :)) batch file to illustrate my problem:

@Echo Off
SetLocal
Set Pad="%@Repeat[ ,7]"
For /L %IDX in (0,1,6) Do (
@Echo %@Left[7,%@Left[%IDX,ABCDEFG]%@UnQuote[%Pad]] ---
)
EndLocal
Quit 0

Here's the output I get:

A ---
AB ---
ABC ---
ABCD ---
ABCDE ---
ABCDEF ---

Here's the output I want (due to the same formatting issues with this website you have to pretend that the tildes are blanks):

A~~~~~~---
AB~~~~~---
ABC~~~~---
ABCD~~~---
ABCDE~~---
ABCDEF~---


Is there any way I can actually get the output I want???
 
#2
A long-standing rule, a legacy of COMMAND.COM, is that environment variables
cannot (normally) have trailing spaces. Starting with 4DOS.COMRex has
provided a work-around, to wit, put two consecutive "back-ticks" after the
trailing spaces in the SET command, and they will stick. In your case:

set space7=%@repeat[ ,7]``

Note that you do not need quotation marks around the spaces, hence you can
use the value without @unquote[].

BTW, spaces, commas, and other special characters in filenames are virtually
unique to the Windows long file names, while the underscore _ character is
acceptable in most file systems. Many websites use Unix/Linux file systems,
so I would not change other characters to spaces. This, however, is a
personal preference.
--
HTH, Steve
 
#3
I can't explain why yours fails but there are alternatives. Perhaps @UNQUOTE also removes surrounding spaces. This works as well with '~' replaced by a space.

Code:
v:\> set str=ABCDEFG
v:\> for /L %i in (1,1,7) echo %@left[%i,str]%@repeat[~,%@eval[7-%i]]---
A~~~~~~---
AB~~~~~---
ABC~~~~---
ABCD~~~---
ABCDE~~---
ABCDEF~---
ABCDEFG---
 
M

mathewsdw@sbcglobal.net

Guest
#5
Thank you for thinking about my problem! Fortunately, Steve Fábián provided me with a simple solution to the problem! (As I stated in my repy to Steve, I don't fully understand why the double-quotes don't work, but who cares!)