dict.txt file sorting

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
legend maxfreak
Posts: 73
Joined: 03 Sep 2017, 04:35

dict.txt file sorting

13 Nov 2017, 13:27

I have a dict.txt file containing all the English words of length 1>>>>>, so how do i sort my dict.txt file to contain words of length 3> (3 words and above till infinity) only, 4>(4 and above) only, 5>, 6>, 7>, 8> and so many other to my likeness
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: dict.txt file sorting

13 Nov 2017, 15:22

Try this, you can use FileRead,dict,dict.txt or Loop,Read, dict.txt to read file contents:

Code: Select all

dict:="
(
two
key
AutoHotkey
length
what
about
me
get
find
search
long
alphabet
)"
max:=0
Loop,Parse,dict,`n,`r
  If (StrLen(A_LoopField)>max)
   max:=StrLen(A_LoopField)
obj:=[]
Loop % max
  obj.Push([])
Loop,Parse,dict,`n,`r
  obj[StrLen(A_LoopField)].Push(A_LoopField)
for k,v in obj
  for k,v in v
    output.=v "`n"
output:=RTrim(output,"`n")
MsgBox % output
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: dict.txt file sorting

13 Nov 2017, 15:50

Here's a try:

Code: Select all

q:: ;sort list by length/by length and alphabetically
vText := " ;continuation section
(
two
key
AutoHotkey
length
what
about
me
get
find
search
long
alphabet
)"

;sorted by length then alphabetically
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2*2)
Loop, Parse, vText, `n, `r
	vOutput .= Format("{:04}", StrLen(A_LoopField)) A_LoopField "`n"
Sort, vOutput
MsgBox, % "[" vOutput "]"
vOutput := RegExReplace(vOutput, "(^|`n)\K....")
vOutput := StrReplace(vOutput, "`n", "`r`n")
MsgBox, % "[" vOutput "]"

;sorted by length
oArray := {}
Loop, Parse, vText, `n, `r
	oArray[StrLen(A_LoopField)] .= A_LoopField "`r`n"
vOutput := ""
for vKey, vValue in oArray
	vOutput .= vValue
MsgBox, % "[" vOutput "]"
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Guest

Re: dict.txt file sorting

13 Nov 2017, 17:10

Amazing the help you guys give to people with no interest in learning anything (and its fairly obvious it is going to be used for s p a m purposes given the other posts by the OP on how to "paste" in whatsapp). If he even googled he would found various solutions already.
User avatar
legend maxfreak
Posts: 73
Joined: 03 Sep 2017, 04:35

Re: dict.txt file sorting

13 Nov 2017, 17:45

Guest wrote:Amazing the help you guys give to people with no interest in learning anything (and its fairly obvious it is going to be used for s p a m purposes given the other posts by the OP on how to "paste" in whatsapp). If he even googled he would found various solutions already.
Its not for s p a m purpose sir
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: dict.txt file sorting

14 Nov 2017, 01:56

Pretty much a textbook case for a custom sort function.

Code: Select all

vText := " ;continuation section
(
two
key
AutoHotkey
length
what
about
me
get
find
search
long
alphabet
)"

Sort, vText, F Sort_Custom
MsgBox % vText

Sort_Custom(a,b)
{
	if (L := StrLen(a) - StrLen(b))
		return L
	return a > b ? 1 : a < b ? -1 : 0
}
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: dict.txt file sorting

14 Nov 2017, 02:15

Gast wrote:Amazing the help you guys give to people with no interest in learning anything (and its fairly obvious it is going to be used for s p a m purposes given the other posts by the OP on how to "paste" in whatsapp). If he even googled he would found various solutions already.
Hi fellow pre-crime investigator! :thumbup:
Erm, wait ... you are supporting spammers with advising them to search via Google bc you know that there are already various spamming solutions available?! :wtf:

https://i.imgflip.com/ug71e.jpg
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: dict.txt file sorting

14 Nov 2017, 02:26

Guest wrote:Amazing the help you guys give to people with no interest in learning anything (and its fairly obvious it is going to be used for s p a m purposes given the other posts by the OP on how to "paste" in whatsapp). If he even googled he would found various solutions already.
I answer post for about the same reason others might do crossword puzzles.

It entertains me, exercises my brain, and increases my knowledge.

So I tend to only answer questions that entertain me in some way.

Which means I answer questions in the "Gaming" section less and less even though that is where I started as the questions are very repetitive, simple, incoherent or near impossible.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mankvl, OrangeCat, sanmaodo, zerox and 294 guests