AutoHotkey Community

It is currently May 27th, 2012, 9:12 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Alignment Problem
PostPosted: November 21st, 2011, 11:17 pm 
Offline

Joined: November 15th, 2011, 5:44 pm
Posts: 4
I'm trying to create a hotkey that will convert selected text such as this:
Code:
nlast = "smith"
nfirst = "john"
nstreet = "1234 Anywhere Ave"
nstate = "OK"


Into this:
Code:
nlast   = "smith"
nfirst  = "john"
nstreet = "1234 Anywhere Ave"
nstate  = "OK"


The part to determine the furthest position of the equals is working (alignto), but the part that is trying to determine the position of the first space is not. Here is the code:

Code:

F7::
 alignto = 0
 Clipboard =
 Send, ^c
 ClipWait
 Loop, parse, clipboard, `n, `r
 {
  Haystack = %A_LoopField%
  Needle = `=
  StringGetPos, pos, Haystack, %Needle%
  MsgBox, %A_LoopField% `n %pos%
  if (pos > alignto)
  {
    alignto = %pos%
  }
 }
 MsgBox, %alignto%

 Loop, parse, clipboard, `n, `r
 {
  Haystack = %A_LoopField%
  Needle = %A_Space%
  StringGetPos, pos, Haystack, %Needle%
  MsgBox, %A_LoopField% `n %pos%
 }
return


Can anyone tell me what's going wrong here?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2011, 11:52 pm 
Offline

Joined: February 17th, 2008, 8:52 pm
Posts: 314
If the first part of each line never changes then you can use StringReplace:

Code:
F7::
   Clipboard :=
   Send, ^c
   ClipWait
   StringReplace, clipboard, clipboard, nlast, nlast%A_Space%%A_Space%
   StringReplace, clipboard, clipboard, nfirst, nfirst%A_Space%
   StringReplace, clipboard, clipboard, nstate, nstate%A_Space%
   Send, ^v
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2011, 12:18 am 
Offline

Joined: August 7th, 2011, 1:23 pm
Posts: 754
If you can accept a predefined first-field-length you can use this:
Code:
pad := "         " ; you need to change just the padding length
loop, parse, clipboard, `n,`r
{   
   RegExMatch(A_LoopField, "\s*(.*)\s*=\s*(.*)\s*", v)
   outVar .= v1 <> "" ? substr(v1 pad, 1, StrLen(pad))  "= " v2 "`n" : ""
}
clipboard := outvar
send ^v

_________________
Win7 - Firefox 10.0.2 - AHK_L 1.1.07.00
Please bear with me and my English which is so bad at times that even I don't understand myself


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2011, 12:37 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
You might want to try SKAN's SetWidth() function.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google Feedfetcher and 67 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group