Batch file decides that 4 > 39, How do I fix it?

后端 未结 3 1667
一整个雨季
一整个雨季 2021-01-24 22:36

Note: The file Default.txt contains one line with these three characters:1:X

    @echo off
    set r=0
    :: For loop retrieves lines of text f         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-24 23:35

    Prudviraj's answer answers why your original code doesn't work, but for an easier way of padding a string to 39 characters, you could try:

    Make39.bat

    @echo off
        setlocal
        set "R=%1"
        set "R=%R%                                       "   REM append 39 spaces
        set "R=%R:~,39%"                                     REM take first 39 characters
        echo :123456789012345678901234567890123456789:
        echo :%R%:
    

    which works as follows:

    S:\>make39 abc
    :123456789012345678901234567890123456789:
    :abc                                    :
    
    S:\>make39 "Quite a long string"
    :123456789012345678901234567890123456789:
    :Quite a long string                    :
    

    Your comments seem to imply no string will initially be longer than 39 characters; you would have to get more inventive if this were possible (I would probably take the first 39 characters of the original R and see if that and R differ: if they did, the original would have been longer, so there would be no need to add padding).

提交回复
热议问题