Help with finding these characters ( | )and backspacing them out.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sixstringgrips
Posts: 6
Joined: 06 May 2021, 16:33

Help with finding these characters ( | )and backspacing them out.

06 May 2021, 16:44

Code: Select all

~::
Send ^a ;select all
Sleep, 50
Send ^x ;cut
Sleep 50
Clipboard:=StrReplace(Clipboard,"|","") ;replace line with space
Sleep, 100
;~ MsgBox % Clipboard
Send ^v ;send paste
;~ Sleep, 150
return
[Mod edit: [code][/code] tags added.]
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Help with finding these characters ( | )and backspacing them out.

06 May 2021, 17:16

Is the script working? Is there a question about it?
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Help with finding these characters ( | )and backspacing them out.

06 May 2021, 20:50

If you want | replaced with a space then:

Code: Select all

Clipboard:=StrReplace(Clipboard,"|"," ") ;replace line with space
sixstringgrips
Posts: 6
Joined: 06 May 2021, 16:33

Re: Help with finding these characters ( | )and backspacing them out.

07 May 2021, 05:27

Original text

IF THE STANDBY ENGINE INDICATOR MUST BE REMOVED FOR ANY REASON, | | |
| DO NOT TOUCH THE SEI BEFORE YOU DO THE PROCEDURE FOR DEVICES | | |
| THAT ARE SENSITIVE TO ELECTROSTATIC DISCHARGE (AMM 20-41-01). | | |
| ELECTROSTATIC DISCHARGE CAN DAMAGE THE SEI.



After my Script

IF THE STANDBY ENGINE INDICATOR MUST BE REMOVED FOR ANY REASON,



DO NOT TOUCH THE SEI BEFORE YOU DO THE PROCEDURE FOR DEVICES



THAT ARE SENSITIVE TO ELECTROSTATIC DISCHARGE (AMM 20-41-01).



ELECTROSTATIC DISCHARGE CAN DAMAGE THE SEI.


This is how it should be.

IF THE STANDBY ENGINE INDICATOR MUST BE REMOVED FOR ANY REASON,
DO NOT TOUCH THE SEI BEFORE YOU DO THE PROCEDURE FOR DEVICES THAT
ARE SENSITIVE TO ELECTROSTATIC DISCHARGE (AMM 20-41-01). ELECTROSTATIC
DISCHARGE CAN DAMAGE THE SEI.

What I have to do now is put my cursor before the | and backspace 8 times
manually for each instance. In the (Original text) example above, I have 3 instances of those bars (|)
I beleive there are carriage returns and spaces that are causing the (After my scrip) condition.
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Help with finding these characters ( | )and backspacing them out.

07 May 2021, 07:15

Code: Select all

str =
(
IF THE STANDBY ENGINE INDICATOR MUST BE REMOVED FOR ANY REASON, | | |
| DO NOT TOUCH THE SEI BEFORE YOU DO THE PROCEDURE FOR DEVICES | | |
| THAT ARE SENSITIVE TO ELECTROSTATIC DISCHARGE (AMM 20-41-01). | | |
| ELECTROSTATIC DISCHARGE CAN DAMAGE THE SEI.
)
SendInput % new := RegExReplace(str, "m`a)(^[|\h]+|[|\h]+$)")
sixstringgrips
Posts: 6
Joined: 06 May 2021, 16:33

Re: Help with finding these characters ( | )and backspacing them out.

07 May 2021, 19:15

Forgive the ignorance, but where would I insert that code into my existing? Keep in mind that what I provided was sample text, and every time I press the tilda I would want the script to examine the clipboard text for the bars and remove them while backspacing where those occurred.
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Help with finding these characters ( | )and backspacing them out.

07 May 2021, 19:37

Code: Select all

~::
Clipboard =
Send ^a^x
ClipWait, 0
If ErrorLevel {
 MsgBox, 48, Error, An error occurred while waiting for the clipboard. Aborting.
 Return
} Else str := Clipboard, Clipboard := "", Clipboard := RegExReplace(str, "m`a)(^[|\h]+|[|\h]+$)")
ClipWait, 0
If ErrorLevel
 MsgBox, 48, Error, An error occurred while waiting for the clipboard. Aborting.
Else Send ^v
Return
A simple alternative regex:

Code: Select all

RegExReplace(str, "\|\h*")
Or:

Code: Select all

RegExReplace(str, " ?\| ?")
sixstringgrips
Posts: 6
Joined: 06 May 2021, 16:33

Re: Help with finding these characters ( | )and backspacing them out.

08 May 2021, 06:30

As I tried your first code reply, I got an error saying "An error occurred while waiting on the clipboard. Aborting." If I didn't mention it.... I would like to select the text needed from a PDF, then press tilde, which will copy the highlighted text to the clipboard and "clean it up", then place my cursor in the desired field with the mouse and press control-v to display the cleaned up text.
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Help with finding these characters ( | )and backspacing them out.

08 May 2021, 07:45

Different question, different script.

Code: Select all

~::
Clipboard =
Send ^c
ClipWait, 0
If ErrorLevel
 MsgBox, 48, Error, An error occurred while waiting for the clipboard. Aborting.
Else Clipboard := RegExReplace(Clipboard, "m`a)(^[|\h]+|[|\h]+$)")
Return
sixstringgrips
Posts: 6
Joined: 06 May 2021, 16:33

Re: Help with finding these characters ( | )and backspacing them out.

08 May 2021, 09:15

Thank you so much...works perfectly. You're script is going to save me a ton of time.
sixstringgrips
Posts: 6
Joined: 06 May 2021, 16:33

Re: Help with finding these characters ( | )and backspacing them out.

11 May 2021, 11:56

I haven't changed anything in the script and I'm not able to get the results I expected.

The problem only occurs when I'm copying multi line text from a PDF. When I paste, it comes in like this: (See attachments please)

The lines are gone now, but the text doesn't come together as expected.
Attachments
correct.JPG
correct.JPG (26.04 KiB) Viewed 251 times
Wrong.JPG
Wrong.JPG (26.65 KiB) Viewed 251 times
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Help with finding these characters ( | )and backspacing them out.

11 May 2021, 18:01

I cannot work with an image of text, but if you wish to replace the line feeds with spaces, you can likely use StrReplace to achieve that without much trouble. An example of a similar approach is below.

Code: Select all

str =
(
IF THE STANDBY ENGINE INDICATOR MUST BE REMOVED FOR ANY REASON, | | |
| DO NOT TOUCH THE SEI BEFORE YOU DO THE PROCEDURE FOR DEVICES | | |
| THAT ARE SENSITIVE TO ELECTROSTATIC DISCHARGE (AMM 20-41-01). | | |
| ELECTROSTATIC DISCHARGE CAN DAMAGE THE SEI.
)
SendInput % new := RegExReplace(str, "m`a)(^[|\h]+|(\| ?)+\n)")

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot] and 116 guests