Jump to content

Text Name Sorter...


 Share

Recommended Posts

B) I was wondering if anyone has made something that organized names in a text editor.

Say if there were these names.....

Andrew

Josh

Nick

Zack

Andrew

Nick

Nick

Josh

Andrew

.....It would put them in order, like all the Andrews in one spot, then all the Nicks, etc...

So when it got done organizing it would look something like this.....

Andrew

Andrew

Andrew

Josh

Josh

Nick

Nick

Nick

Zack

If someone made or will make a program to do this, please let me know!

Thanks :o!

Link to comment
Share on other sites

  • Moderators

_ArrayCreate() / _ArraySort()? in the help file... B)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

...guessing is not any fun...

...but I'll do it anyway... :-(

@hlstriker,

Are you wanting to sort these names before saving them as a text file?

Do you want to sort them within the editor interface???

......If yes, then using Notepad as an example:

#include <Array.au3>

WinWait("Untitled - Notepad")
WinActivate("Untitled - Notepad")
WinWaitActive("Untitled - Notepad")
Send("^a")
Send("^x")

$textARRAY = StringSplit(ClipGet(), @CRLF, 1)
_ArraySort($textARRAY, 0, 1)

For $i = 1 To $textARRAY[0]
    WinWait("Untitled - Notepad")
    WinActivate("Untitled - Notepad")
    WinWaitActive("Untitled - Notepad")
    Send($textARRAY[$i])
    Send(@CR)
Next
......If no, then post the code that is not working for you.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

good guessing plato... bravo

i played with it a little... doesnt need my winactivate

just needs a title

#include <Array.au3>

$Title = "Untitled - Notepad"

If Not WinExists($Title) Then
    MsgBox(64,"Error", $Title & " is not available  ")
    Exit
EndIf

WinActivate($Title)
ControlSend($Title,"","Edit1","^a")
ControlSend($Title,"","Edit1","^c")
$textARRAY = StringSplit(ClipGet(), @CRLF, 1)
_ArraySort($textARRAY, 0, 1)

For $i = 2 To $textARRAY[0]
    ControlSend($Title,"","Edit1",($textARRAY[$i]))
    ControlSend($Title,"","Edit1", @CR)
Next

i noticed i had to put

For $i = 2 To $textARRAY[0]

because the first array was a null

8)

NEWHeader1.png

Link to comment
Share on other sites

...exactly what I wanted...

Great!

Now to complicate things just a little. If a Windows clipboard operation involving a large amount of data occurs just before you run that script - functions like ClipGet and ClipPut may not execute as expected... also, operations like ctrl-c, ctrl-v and ctrl-x might fail. You should build in some checks and/or live with long sleeps sprinkled throughout your code.

This code is not going to work well with large amounts of text, but it may do what you want. You can speed it up a bit with "OPT" settings.

AutoItSetOption("SendKeyDelay", 1)
AutoItSetOption("WinWaitDelay", 1)

#include <Array.au3>

;Do not proceed until the clipboard is empty
While 1
    ClipPut("")
    Sleep(100)
    If ClipGet() == "" Then ExitLoop
WEnd

WinWait("Untitled - Notepad")
WinActivate("Untitled - Notepad")
WinWaitActive("Untitled - Notepad")
Send("^a")
Sleep(200)
Send("^x")
Sleep(200)

$textARRAY = StringSplit(ClipGet(), @CRLF, 1)
_ArraySort($textARRAY, 0, 1)

For $i = 1 To $textARRAY[0]
    WinWait("Untitled - Notepad")
    WinActivate("Untitled - Notepad")
    WinWaitActive("Untitled - Notepad")
    Send($textARRAY[$i])
    Send(@CR)
Next
....have fun...

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

...For $i = 2 To $textARRAY[0]

because the first array was a null...

If you did what I did to build a test within notepad, then you probably put a few lines in notepad that ended in a blank line (CR). Then ctrl-a, ctrl-c, ctrl-v, ctrl-v, ctrl-v, ctrl-v, ctrl-v, ... Then run the script and you will get the CR at the top of the sort. If your sample text has no CR on the last line, then $i = 1 to ... should work. At least it did for me.

Caveat = I may not be using CR, LF and CRLF terms correctly.

...and I tend to overuse:

WinWait

WinActivate

WinWaitActive

...but it is only code :-)

EDIT1:

@hlstriker,

The ControlSend that Valuater used is much better in most cases. Take a look at the help file and the AutoIt window info tool.

EDIT2:

@Valuater,

Glad that you mentioned the for/next loop number - I thought of posting about that in my first post (but forgot to) that you might have to edit out a blank line at the top if your "names" end in a blank line. If they will always end in a blank line, then change the 1 to a 2 in the for/next loop as you mentioned. [and thanks for the compliment in the post below]

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...