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 

Split text in clipboard

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



Joined: 12 Oct 2006
Posts: 99
Location: Canada

PostPosted: Sat Jan 10, 2009 12:47 am    Post subject: Split text in clipboard Reply with quote

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... Rolling Eyes
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.
Back to top
View user's profile Send private message
evan
Guest





PostPosted: Sat Jan 10, 2009 4:14 am    Post subject: Reply with quote

is the data lines always equal?
Back to top
[VxE]



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

PostPosted: Sat Jan 10, 2009 4:58 am    Post subject: Reply with quote

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

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
edu



Joined: 12 Oct 2006
Posts: 99
Location: Canada

PostPosted: Sat Jan 10, 2009 9:22 pm    Post subject: Reply with quote

Thank You, [VxE]! I never thought the stringsplit would do the job!

Edu
_________________
The best things of life are free.
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