Create a small Dictionary [ A B C ]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alid0381
Posts: 28
Joined: 09 May 2012 10:37

Create a small Dictionary [ A B C ]

#1 Post by alid0381 » 29 Aug 2016 10:43

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.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Create a small Dictionary [ A B C ]

#2 Post by Aacini » 29 Aug 2016 11:04

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?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Create a small Dictionary [ A B C ]

#3 Post by aGerman » 29 Aug 2016 11:27

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

alid0381
Posts: 28
Joined: 09 May 2012 10:37

Re: Create a small Dictionary [ A B C ]

#4 Post by alid0381 » 30 Aug 2016 10:40

Tanks Acini;

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

alid0381
Posts: 28
Joined: 09 May 2012 10:37

Re: Create a small Dictionary [ A B C ]

#5 Post by alid0381 » 30 Aug 2016 10:45

Thanks aGerman :
Now, It's working..

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Create a small Dictionary [ A B C ]

#6 Post by foxidrive » 31 Aug 2016 13:58

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.

alid0381
Posts: 28
Joined: 09 May 2012 10:37

Re: Create a small Dictionary [ A B C ]

#7 Post by alid0381 » 04 Sep 2016 10:43

Tanks foxidrive; But:

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

Post Reply