Padding with blanks...

  • Thread starter mathewsdw@sbcglobal.net
  • Start date
M

mathewsdw@sbcglobal.net

Guest
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???
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
 
May 20, 2008
12,165
133
Syracuse, NY, USA
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
...
set space7=%@repeat[ ,7]``
...

Thanks, Steve! That did the trick! (I must admit that I don't quite understand why the double-quotes didn't work, but that's quite irrelevant at this point...).

- Dan
 
M

mathewsdw@sbcglobal.net

Guest
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!)