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

Get help with using AutoHotkey and its commands and hotkeys
kwfine
Posts: 16
Joined: 26 Nov 2015, 06:46

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

26 Mar 2016, 04:50

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
User avatar
Spawnova
Posts: 339
Joined: 08 Jul 2015, 00:12
Contact:

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

26 Mar 2016, 05:18

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
Last edited by Spawnova on 26 Mar 2016, 05:19, edited 1 time in total.
garry
Posts: 1978
Joined: 22 Dec 2013, 12:50

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

26 Mar 2016, 05:18

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%
kwfine
Posts: 16
Joined: 26 Nov 2015, 06:46

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

26 Mar 2016, 05:55

Thank you Spawnova, and garry for your quick help!!! :D
User avatar
Spawnova
Posts: 339
Joined: 08 Jul 2015, 00:12
Contact:

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

26 Mar 2016, 06:05

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
kwfine
Posts: 16
Joined: 26 Nov 2015, 06:46

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

26 Mar 2016, 06:09

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?
garry
Posts: 1978
Joined: 22 Dec 2013, 12:50

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

26 Mar 2016, 07:49

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,
User avatar
tidbit
Posts: 1154
Joined: 29 Sep 2013, 17:15
Location: USA

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

26 Mar 2016, 11:11

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,"[()[\]{}]"," ")
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
Spawnova
Posts: 339
Joined: 08 Jul 2015, 00:12
Contact:

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

26 Mar 2016, 12:05

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

Return to “Ask For Help”

Who is online

Users browsing this forum: Alexzemm, Chunjee, enrica, Google [Bot], jmasiak, jNizM, sdkyron and 227 guests