Вопрос

I am trying to make a decoder from a batch file. It takes my input and turns it into an output by looking at each character. Here is what I have.

@Echo Off
:StartUpConfiguration
Cls
Color 0A
Mode Con Cols=60 Lines=35
Title Decoder

:Input
Set /P Input=[Enter Input Here]

At this point I want it to read the first three characters which will either be "(0)" or "(1)" and then from there make the fourth character set 0's or 1's corresponding to the first three characters. Ex) If my input is "(1)3241", i want my output to be "1110011110" which makes the first numbers 1's from the "(1), then making three of that number, then alternate to a zero and make two 0's and so forth. The pattern tells it what number to start with (1 or 0), and then create how ever many of that number corresponding to the next number in the input.

I have seen tokens used to pull a certain area from a string of text.

Это было полезно?

Решение

@echo off
setlocal EnableDelayedExpansion

Set /P Input=[Enter Input Here]

for /F "tokens=1,2 delims=()" %%a in ("%input%") do (
   set bit=%%a
   set "output="
   for /F "delims=" %%c in ('cmd /D /U /C echo %%b^| find /V ""') do (
      for /L %%i in (1,1,%%c) do set "output=!output!!bit!"
      set /A "bit=^!bit"
   )
)
echo %output%
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top