AutoHotkey Community

It is currently May 26th, 2012, 1:59 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Split text in clipboard
PostPosted: January 10th, 2009, 1:47 am 
Offline

Joined: October 12th, 2006, 9:57 pm
Posts: 99
Location: Canada
Hello I am trying to copy and paste some text from several html files to an ms excel file.
The text is copied to the clipboard like this:
NEW NAME
UC 900-640-O Light Blue
UC 900-645-O Peacock Blue
UC 900-650-O Powder Blue
OLD NAME
A9540-O Light Blue
A9545-O Peacock Blue
A9550-O Powder Blue

I want to be able to paste NEW NAME and data below in one column and the OLD NAME in the next column. Basically I wish to transform the data into this:
NEW NAME{TAB}OLD NAME
One of the approaches I thought of was: create a variable to hold the contents of "NEW NAME", paste it in column 1; insert everything from OLD NAME on into a new variable and paste it in column 2.
Another approach could be generating a tab delimited file.
Then I got stuck in the loop construct... :roll:
This was what I started trying:
Code:
NewCode = ""
OldCode = ""
Loop, parse, clipboard, `n, `r
{
   NewCode += A_LoopField
   if (A_LoopField == "OLD NAME")
   {
   Break
   }
   
}


Could you please help me finish this code?
Thanks
Edu

_________________
The best things of life are free.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2009, 5:14 am 
is the data lines always equal?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2009, 5:58 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3329
Location: Simi Valley, CA
Code:
testtext =
(
NEW NAME
UC 900-640-O Light Blue
UC 900-645-O Peacock Blue
UC 900-650-O Powder Blue
OLD NAME
A9540-O Light Blue
A9545-O Peacock Blue
A9550-O Powder Blue
)

clipboard := testtext
StringReplace, clipboard, clipboard, OLD NAME, ¿
StringReplace, clipboard, clipboard, NEW NAME
StringSplit, text, clipboard, ¿, `r`n `t
StringSplit, old, text2, `n, `r
Loop, Parse, text1, `n, `r
{
   Keywait, LCtrl, d
   Keywait, LCtrl ; press and release left control to 'walk through' the data
   SendRaw, %A_LoopField%
   Send, {tab}
   SendRaw, % old%A_Index%
}
return

:?:

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2009, 10:22 pm 
Offline

Joined: October 12th, 2006, 9:57 pm
Posts: 99
Location: Canada
Thank You, [VxE]! I never thought the stringsplit would do the job!

Edu

_________________
The best things of life are free.


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, Exabot [Bot], patgenn123, Pietro, poserpro and 10 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