Page 1 of 1

Create a small Dictionary [ A B C ]

Posted: 29 Aug 2016 10:43
by alid0381
everybody
Thank you so much.
I want to make a small batch to create a small dictionary :

Code: Select all

@echo off
setlocal enableDelayedExpansion
(
   (
            call :One
   ) < "SOURC.txt"
) > "Out-Dic.txt"

endlocal
goto :eof

:One
   set "bu="
   set "input="
   set /P "input="
   set "buffer= !input!"
   set "Next="
   set i=0
:Two
   set "lastByte=!buffer:~1,1!"
   if defined lastByte (
      set "bu=!bu!!Next!!buffer:~1,1!"
rem       echo(!bu!
      echo(!Next!!buffer:~1,1!
       set "buffer=!buffer:~0,1!!buffer:~2!"
      goto :Two
   ) else if defined input (
      set /A i+=1
      set "Next=!input:~%i%,1!"
      set "buffer= !input!"
      if defined Next goto :Two
                            )
                        goto :eof


the SOURC.txt Contain:
abc

Bat I would like an out as follows ,Out-Dic.txt:
a
b
c
aa
ab
ac
ba
bb
bc
aaa
aab
aac
aba
abb
...
cccc.

Re: Create a small Dictionary [ A B C ]

Posted: 29 Aug 2016 11:04
by Aacini
Why

Code: Select all

ca
cb
cc

are not included in the output example?

How the program know that the output limit is 4 characters?

I strongly suggest you to describe your program using plain English, besides the inclusion of code.

Antonio

PS - Did you read these indications already?

Re: Create a small Dictionary [ A B C ]

Posted: 29 Aug 2016 11:27
by aGerman
Generally I agree with Antonio.

Just to give you a hint how to use FOR /L loops for your task:

Code: Select all

@echo off &setlocal
set /p "string="<"SOURC.txt"

setlocal EnableDelayedExpansion
>"Out-Dic.txt" (
  for /l %%i in (0 1 2) do (
    echo !string:~%%i,1!
    for /l %%j in (0 1 2) do (
      echo !string:~%%i,1!!string:~%%j,1!
      for /l %%k in (0 1 2) do (
        echo !string:~%%i,1!!string:~%%j,1!!string:~%%k,1!
        for /l %%l in (0 1 2) do (
          echo !string:~%%i,1!!string:~%%j,1!!string:~%%k,1!!string:~%%l,1!
        )
      )
    )
  )
)

Steffen

Re: Create a small Dictionary [ A B C ]

Posted: 30 Aug 2016 10:40
by alid0381
Tanks Acini;

a
b
c
aa
ab
ac
ba
bb
bc
ca
cb
cc
aaa
aab
aac
aba
abb
...
cccc.

Re: Create a small Dictionary [ A B C ]

Posted: 30 Aug 2016 10:45
by alid0381
Thanks aGerman :
Now, It's working..

Re: Create a small Dictionary [ A B C ]

Posted: 31 Aug 2016 13:58
by foxidrive
It's nice of you to ackowledge aacini - but you supplied no extra information here.

I'm only pointing this out for you to consider a situation where it was you that was helping people with a programming task and they only showed you this kind of non-information.

alid0381 wrote:Tanks Acini;

a
b
c
aa
ab
ac
ba
bb
bc
ca
cb
cc
aaa
aab
aac
aba
abb
...
cccc.

Re: Create a small Dictionary [ A B C ]

Posted: 04 Sep 2016 10:43
by alid0381
Tanks foxidrive; But:

I find it hard in the translation
however,
Will not remain
The downside to pose problems