Sign in to follow this  
Followers 0
beb7089

modify clipboard contents

11 posts in this topic

I trying to figure out how to take the current clipboard contents, modify the contents and then write the contents back to the clipboard to the I can place that text into an application.

Here is a sample of the original clipboard text:

1 Pilot (1) 9/18/1978 0311-0303-0768 Reviews 9.17

2 Pilot (2) 9/25/1978 8008 Reviews 9.00

3 Les On a Ledge 10/2/1978 8010 Reviews 8.83

4 Hoodlum Rock 10/9/1978 8007 Reviews 8.46

Here is how the text should look after processing it:

Pilot (1) (9/18/1978)

Pilot (2) (9/25/1978)

Les On a Ledge (10/2/1978)

Hoodlum Rock (10/9/1978)

Here is the script I have so far. Please help.

$string = ClipGet()

$output = StringTrimLeft ($string, StringInStr ($string,' ',0,1)-1)

$output2 = StringLeft ($output, StringInStr ($output,'/',0,1)-1)

$output3 = StringTrimRight ($output2, 3)

$output4 = StringStripWS ($output3,3)

Thanks

Brandon

Share this post


Link to post
Share on other sites



ClipPut("Sometext") for returning the data


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

See how you get on with this, there may be a more elegant way to do it mind!

#include <array.au3>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;you can comment this out in your real situation but I needed it to test;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$string = "1 Pilot (1) 9/18/1978 0311-0303-0768 Reviews 9.17 " & @crlf & _
"2 Pilot (2) 9/25/1978 8008 Reviews 9.00" & @crlf & _
"3 Les On a Ledge 10/2/1978 8010 Reviews 8.83" & @crlf & _ 
"4 Hoodlum Rock 10/9/1978 8007 Reviews 8.46"

ClipPut($String)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;############################################;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;



;Here is how the text should look after processing it:
;
;Pilot (1) (9/18/1978) 
;Pilot (2) (9/25/1978)
;Les On a Ledge (10/2/1978)
;Hoodlum Rock (10/9/1978)
;
;
;Here is the script I have so far. Please help.

;I broke this down so it was easier to read you could have used $cstring = StringSplit(StringReplace(ClipGet(),@crlf,"|"),"|")
$cString = ClipGet()
$cString = StringReplace($cString,@crlf,"|")
$cstring = StringSplit($cString,"|")


_ArrayDisplay($cString,"This is the start string in an array")

For $i = 1 to Ubound ($cstring) -1
    $cString[$i]=StringTrimLeft($cString[$i],2);cuts the number off the string
    $findTheDate = StringRegExp($cString[$i],"([0-9]{0,2}/[0-9]{0,2}/[1-9]{4})",3);finds the date
    If NOT @error then 

        $pos = StringInstr($cString[$i],$findTheDate[0]) -1
        $date = "(" & $findTheDate[0] & ")"
        $cString[$i]= StringLeft($cString[$i],$pos) & $date

    EndIf
Next

_ArrayDisplay($cString,"This is the new modified array stripping the data you don't want")

$output = ""

For $i = 1 to Ubound($cstring) -1
    $output &=$cstring[$i] & @CRLF
Next

If StringRight($output,2) = @crlf then $output = StringTrimRight($Output,2)

Msgbox(0,"This is the new output",$output)

ClipPut($Output)

Share this post


Link to post
Share on other sites

It appears that what you have in this example is text selected from a table in from TV.com. Perhaps you could include IE.au3, navigate to the site, and use _IETableWriteToArray and manipulate the arrays from there. (Just a thought.) :)

Share this post


Link to post
Share on other sites

See how you get on with this, there may be a more elegant way to do it mind!

#include <array.au3>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;you can comment this out in your real situation but I needed it to test;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$string = "1 Pilot (1) 9/18/1978 0311-0303-0768 Reviews 9.17 " & @crlf & _
"2 Pilot (2) 9/25/1978 8008 Reviews 9.00" & @crlf & _
"3 Les On a Ledge 10/2/1978 8010 Reviews 8.83" & @crlf & _ 
"4 Hoodlum Rock 10/9/1978 8007 Reviews 8.46"

ClipPut($String)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;############################################;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;
;Here is how the text should look after processing it:
;
;Pilot (1) (9/18/1978) 
;Pilot (2) (9/25/1978)
;Les On a Ledge (10/2/1978)
;Hoodlum Rock (10/9/1978)
;
;
;Here is the script I have so far. Please help.

;I broke this down so it was easier to read you could have used $cstring = StringSplit(StringReplace(ClipGet(),@crlf,"|"),"|")
$cString = ClipGet()
$cString = StringReplace($cString,@crlf,"|")
$cstring = StringSplit($cString,"|")
_ArrayDisplay($cString,"This is the start string in an array")

For $i = 1 to Ubound ($cstring) -1
    $cString[$i]=StringTrimLeft($cString[$i],2);cuts the number off the string
    $findTheDate = StringRegExp($cString[$i],"([0-9]{0,2}/[0-9]{0,2}/[1-9]{4})",3);finds the date
    If NOT @error then 

        $pos = StringInstr($cString[$i],$findTheDate[0]) -1
        $date = "(" & $findTheDate[0] & ")"
        $cString[$i]= StringLeft($cString[$i],$pos) & $date

    EndIf
Next

_ArrayDisplay($cString,"This is the new modified array stripping the data you don't want")

$output = ""

For $i = 1 to Ubound($cstring) -1
    $output &=$cstring[$i] & @CRLF
Next

If StringRight($output,2) = @crlf then $output = StringTrimRight($Output,2)

Msgbox(0,"This is the new output",$output)

ClipPut($Output)

very small point. You need to allow for years with a zero in them

$findTheDate = StringRegExp($cString[$i],"([0-9]{0,2}/[0-9]{0,2}/[0-9]{4})",3);finds the date


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

This is exactly what I needed. I knew an "array" would be involved but I just dont understand how they work yet. Thank you for your experience and work.

Share this post


Link to post
Share on other sites

very small point. You need to allow for years with a zero in them

$findTheDate = StringRegExp($cString[$i],"([0-9]{0,2}/[0-9]{0,2}/[0-9]{4})",3);finds the date

Yes your right, bit of a cock error on my part that

Share this post


Link to post
Share on other sites

And being new at this as well, why:

$cString = StringReplace($cString,@crlf,"|")

$cstring = StringSplit($cString,"|")

...instead of simply:

$cstring = StringSplit($cString,@crlf,1)

gsb


"Did you ever stop to think? ...and forget to restart!"

Share this post


Link to post
Share on other sites

in the help file it says "Caution if you use the macro @CRLF you are referring to a 2 character string so you will generate extra blanks lines." so I always swap them out, I have not tried your way but you could be right

Share this post


Link to post
Share on other sites

#10 ·  Posted

Thank you for your insight.

I do not remember reading that.

gsb


"Did you ever stop to think? ...and forget to restart!"

Share this post


Link to post
Share on other sites

#11 ·  Posted

Or use the flag the comes with StringSplit :)

StringSplit ( "string", "delimiters" [, flag ] )

Parameters

string The string to evaluate.

delimiters One or more characters to use as delimiters.

flag [optional] If flag is 0 (the default), then each character in the delimiter string will mark where to split the string. If flag is 1, then the entire delimiter string is needed to mark the split.

So

StringSplit($cString, @CRLF, 1)

(Which if I may add should be the default and not 0 as now)


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
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
Sign in to follow this  
Followers 0