AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to stop sort inserting empty lines?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Puzzled Greatly



Joined: 15 Aug 2009
Posts: 274

PostPosted: Sun Jan 31, 2010 12:22 am    Post subject: How to stop sort inserting empty lines? Reply with quote

I have the following code:
Code:
#!down::
   clipboard =
   Send, ^c
   clipwait
   sortlist := clipboard
   Sort, sortlist
   send, %sortlist%
return

I tested this in metapad and notepad++. It sorted a list of words (each word on a different line) but it added in an extra line after each word. What have I done wrong?  How can I sort a list of words without adding an extra line of space between each word?

Thanks,

GP   
Back to top
View user's profile Send private message
q&a
Guest





PostPosted: Sun Jan 31, 2010 3:34 am    Post subject: Reply with quote

Yea thats weird..
This seems to fix the problem.
Code:
#!down::
   clipboard =
   Send, ^c
   clipwait
   sortlist := clipboard
   Sort, sortlist
   Loop, parse, sortlsist, `n
      send % A_Loopfield
hth
Back to top
[VxE]



Joined: 07 Oct 2006
Posts: 3254
Location: Simi Valley, CA

PostPosted: Sun Jan 31, 2010 4:13 am    Post subject: Reply with quote

Code:
#!down::
   clipboard =
   Send, ^c
   clipwait
   StringReplace, sortlist, clipboard, `r,, A
   Sort, sortlist
   send, %sortlist%
return

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!
Back to top
View user's profile Send private message
Puzzled Greatly



Joined: 15 Aug 2009
Posts: 274

PostPosted: Sun Jan 31, 2010 11:02 am    Post subject: Reply with quote

Thanks, adding the StringReplace works though I don't get why it should be necessary. Is there any way to make the whole script faster? Right now it's as if each word is pasted individually so an 80 word list takes around 10 seconds to process.

GP
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Jan 31, 2010 11:37 am    Post subject: Reply with quote

Puzzled Greatly wrote:
Thanks, adding the StringReplace works though I don't get why it should be necessary. Is there any way to make the whole script faster? Right now it's as if each word is pasted individually so an 80 word list takes around 10 seconds to process.

GP

Use SendInput instead of Send. Read about the difference in the help file!
Back to top
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Sun Jan 31, 2010 11:41 am    Post subject: Reply with quote

Code:
#!down::
   clipboard =
   Send, ^c
   clipwait
   StringReplace, sortlist, clipboard, `r,, A
   Sort, sortlist
   Clipboard:=sortlist
   send, ^v ; paste

return

_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 3254
Location: Simi Valley, CA

PostPosted: Sun Jan 31, 2010 10:19 pm    Post subject: Reply with quote

Code:
#!down::
   clipboard =
   Send, ^c
   clipwait
   StringReplace, sortlist, clipboard, `r,, A
   Sort, sortlist
   StringReplace, Clipboard, sortlist, `n, `r`n, A
   send, ^v ; paste
return
Embarassed
Text in the clipboard may not paste correctly without the full CRLFs. The 'sort' command uses the newline character as the default delimiter, hence the removal of the carriage returns before the sort.
_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Sun Jan 31, 2010 11:29 pm    Post subject: Reply with quote

Why bother?
Quote:
Dx: Specifies x as the delimiter character, which determines where each item in VarName begins and ends. If this option is not present, x defaults to linefeed (`n), which correctly sorts VarName if its lines end in either LF (`n) or CR+LF (`r`n).
Or am I missing something here?
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 3254
Location: Simi Valley, CA

PostPosted: Mon Feb 01, 2010 2:20 am    Post subject: Reply with quote

I didn't know that about Sort. I should have said that the issue was with Send, which replaces both CR and LF with an enter stroke, thus producing extra lines.
Code:
#!down::
   clipboard =
   Send, ^c
   clipwait
   Sort, clipboard
   send, ^v ; paste
return
Question
_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group