Page 1 of 1

is there a built-in function in AHK that will ignore some characters when Copy

Posted: 26 Mar 2016, 04:50
by kwfine
Hi all,

I am learning how to use AHK to copy the text in a web page.
I have learnt from the AHK web site that the copied text will be stored in Clipboard when I highlight some text and choose Copy.
Here is an example sentence of what I have copied from a web page:
Thanks, AHKScript Support Team(formerly The AutoHotkey Support Team)
As you can see in the above text, there are brackets in it,
I would like to ask if there are any built-in functions in AHK that will ignore some specific characters when I copy the text,
so that when I paste the copied text in a word document, it will become the text without brackets:
Thanks, AHKScript Support Team formerly The AutoHotkey Support Team


Thank you.

Kitty

Re: is there a built-in function in AHK that will ignore some characters when Copy

Posted: 26 Mar 2016, 05:18
by Spawnova
I like to use Regular Expression for these types of things, here's a simple way to remove brackets from the clipboard

Code: Select all

original := "Thanks, AHKScript Support Team(formerly The AutoHotkey Support Team)" ;for testing
new := RegExReplace(original,"\(|\)","") ;change original to clipboard, to use the clipboard contents
msgbox % new
exitapp

Re: is there a built-in function in AHK that will ignore some characters when Copy

Posted: 26 Mar 2016, 05:18
by garry
small example with stringreplace

Code: Select all

;cl:=clipboard
cl=Thanks, AHKScript Support Team(formerly The AutoHotkey Support Team)
stringreplace,cl,cl,(,%a_space%,all
stringreplace,cl,cl,),%a_space%,all
msgbox,%cl%

Re: is there a built-in function in AHK that will ignore some characters when Copy

Posted: 26 Mar 2016, 05:55
by kwfine
Thank you Spawnova, and garry for your quick help!!! :D

Re: is there a built-in function in AHK that will ignore some characters when Copy

Posted: 26 Mar 2016, 06:05
by Spawnova
Those are different characters to your previous example

StringReplace:

Code: Select all

StringReplace,clipboard,clipboard,[,%a_space%,all
StringReplace,clipboard,clipboard,],%a_space%,all
RegEx:

Code: Select all

clipboard := RegExReplace(clipboard,"\(|\)|\[|\]"," ") ;changes () {} to space; change the " " to "" for no space

Re: is there a built-in function in AHK that will ignore some characters when Copy

Posted: 26 Mar 2016, 06:09
by kwfine
garry wrote:small example with stringreplace

Code: Select all

;cl:=clipboard
cl=Thanks, AHKScript Support Team(formerly The AutoHotkey Support Team)
stringreplace,cl,cl,(,%a_space%,all
stringreplace,cl,cl,),%a_space%,all
msgbox,%cl%
Hi garry,
I see in your example that the functon, stringreplace is used two times before the brackets can be removed,
is it the limits of using stringreplace? I mean if it can be done using stringreplace once?

Re: is there a built-in function in AHK that will ignore some characters when Copy

Posted: 26 Mar 2016, 07:49
by garry
I see in your example that the functon, stringreplace is used two times before the brackets can be removed,
is it the limits of using stringreplace? I mean if it can be done using stringreplace once?
I think no , replaces to different strings , string1: ( .... and string2: )
regex example is shorter

another example
replaces ABC with A in text-variable 'CL' ( because parameter ',all' is missing , replaces only once in the text )

Code: Select all

stringreplace,cl,cl,ABC,A,

Re: is there a built-in function in AHK that will ignore some characters when Copy

Posted: 26 Mar 2016, 11:11
by tidbit
spawnova:
it can be shortened by using a [...] group:
every character between [...] is treated as "any of these". and only a few things need to be escaped inside [...]'s (such as ] \ and -. and things like \w \d \s, etc.
clipboard := RegExReplace(clipboard,"[()[\]{}]"," ")

Re: is there a built-in function in AHK that will ignore some characters when Copy

Posted: 26 Mar 2016, 12:05
by Spawnova
tidbit wrote:spawnova:
it can be shortened by using a [...] group:
every character between [...] is treated as "any of these". and only a few things need to be escaped inside [...]'s (such as ] \ and -. and things like \w \d \s, etc.
clipboard := RegExReplace(clipboard,"[()[\]{}]"," ")
Ah, I wasn't sure if they needed an escape inside the group, but that is indeed easier. =P