1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Padding with blanks...

Discussion in 'Support' started by mathewsdw@sbcglobal.net, Jun 18, 2009.

  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. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,939
    Likes Received:
    30
    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---
    
     
  4. 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
     
  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!)
     

Share This Page