logo
down
shadow

Echo x number of dots based on the length of the file name


Echo x number of dots based on the length of the file name

By : Waseem
Date : November 22 2020, 10:48 AM
hop of those help? You can use variable substrings with a for /l loop to determine the length of a string. Keep looping until x number of characters of filename is equal to filename, then you've found your length.
Loop through all files in the directory to find the longest. Then add 5 to that to make sure the longest file still has 5 dots. Then for each file in the directory, that number minus length is the number of dots you need.
code :
@echo off
setlocal enabledelayedexpansion

:: get longest filename in directory
set longest=0
for %%I in (*) do (
    call :length "%%~I" len
    if !len! gtr !longest! set longest=!len!
)

:: Dot fill each line
for %%I in (*) do (
    call :length "%%~I" len
    set /a dots=%longest% + 5 - len
    <NUL set /P "=%%~I"
    call :dots !dots!
    echo %%~zI bytes
)

:: end main script
goto :EOF

:length <filename> <var_to_set>
setlocal enabledelayedexpansion
set "tmpfile=%~1"
for /l %%I in (1,1,100) do (
    if "!tmpfile!"=="!tmpfile:~-%%I!" (
        endlocal && set "%~2=%%I"
        goto :EOF
    )
)

:dots <number_of_dots>
setlocal
for /l %%I in (1, 1, %~1) do <NUL set /P "=."
goto :EOF
:dots <number_of_dots>
setlocal enabledelayedexpansion
set "dots=...................................................................................................."
<NUL set /P "=!dots:~-%1!"
goto :EOF


Share : facebook icon twitter icon
c# Regex is number of length and allow whitespaces and dots

c# Regex is number of length and allow whitespaces and dots


By : Ghassem Rahno
Date : March 29 2020, 07:55 AM
I wish this help you To make it clear, this is just part of what my Input string can be, therefor its important the regex work as a bool, since I only wanna change the input if it looks like v1 & v2. , Try this expression
code :
^(\d{3})[. ](\d{3})[. ](\d)[. ](\d)$
$1$2$3$4
Simple batch file, if number = this echo hello, else echo world

Simple batch file, if number = this echo hello, else echo world


By : 3.1415
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am having trouble creating a simple batch file. All I want to be able to do it have do is generate a random number between 1 and 100 then if that number is less than or equal to 50 have it echo Hello and anything 51+ to echo World.
code :
@echo off&setlocal enabledelayedexpansion
for /l %%i in (1,1,5) do (
title Hello World
set /a hw=!random! %%100 + 1
if !hw! LEQ 50 (
   echo Hello
) else (
   echo World
)
)
pause
Python - Parse file into outputs based on magic number/length

Python - Parse file into outputs based on magic number/length


By : Ranvir Gorai
Date : March 29 2020, 07:55 AM
this will help I'm a complete beginner to coding - only started 3 weeks ago, and really only have codecademy's Python course under my belt - so simple explanations would be really appreciated! , You can try something like this:
code :
filename = "hextests"

# read file as a binary string
with open(filename, "rb") as f:
    content = f.read()

# You don't need this part if you want
# to parse the hex string as it is given in the file   
# convert binary string to hex string
# hexString = binascii.hexlify(content)

# Remove the newline at the end of the string
hexString = content.strip()


# define magic number as "00"
magic_N = "00"

i = 0
j = 0
while i < len(hexString) - 1:
    index = hexString.find(magic_N, i)

    # This is the part which was incorrect in your code.
    with open("output_file_%s.xyz" % j, "wb") as output:
        output.write(hexString[i:i+8])

    i += 8
    j += 1
How do i find the dots closest to the middle with my code (based on number of dots asked)

How do i find the dots closest to the middle with my code (based on number of dots asked)


By : user3216807
Date : March 29 2020, 07:55 AM
I hope this helps you . So I have the following code and I need to find the number of dots closest to the middle of the row that are not '#'. Since in this case I'm looking for 3 dots I need to find the 3 dots closest to the middle and get the starting index of those 3 dots. I need the 3 dots to be next to each other. It can't be hard coded in case I need to change the string and in case I need to change the number of dots I'm looking for. , you can try:
code :
 int numOfDots = 3;
    String line = "...#.#...#";
    String[] arry = line.split("#");

    int middle = arry.length%2==0?arry.length/2:(arry.length/2 +1);

    for (int i=middle,j = middle; i >= 0; i--,j++) {
        if(arry[i].length()==numOfDots) {
            System.out.println("Result Index in arry :" + i);
            break;
        }
        if(j<arry.length&&arry[j].length()==numOfDots) {
            System.out.println("Result Index in arry :" + j);
            break;
        }
    }
Why using echo, unnecessary string length's number also include in message?

Why using echo, unnecessary string length's number also include in message?


By : Justin Castilla
Date : March 29 2020, 07:55 AM
this will help http://php.net/manual/en/function.fwrite.php
fwrite() returns the number of bytes written, or FALSE on error.
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org