Is it possible to stringreplace rtf to clipboard? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
itsfloody
Posts: 4
Joined: 18 Aug 2016, 22:06

Is it possible to stringreplace rtf to clipboard?

07 Mar 2018, 16:54

Hi everyone,
I have a blob of formatted text ,for example:
Car Survey Report

Registration []
Make: []
Model: []
Year: []
Engine: []cc

I want to be able to copy that text to the clipboard,
Read that text line by line and manipulate/replace strings ([] if present),
Then paste the entire clipboard whilst still retaining formatting.

Car Survey Report

Registration EXM357Y
Make:
Model:
Year: 1994
Engine: 3000cc

Is that possible? Many thanks in advance!! Here's my code so far but all I get is plain text
F8::
clipboard =
Txtline2 =
blank = 0
sleep 200
send ^a^c{Home} ;copies all text to clipboard
sleep 400
n = 300

Loop, %n%
{
linet =
needle =
Number := (A_Index)
CurrentEdit := (Edit%Number%)
StringSplit, line, clipboard, `r`n ;splits clipboard into lines
line := % line%Number%
if line =
{
blank := (%blank%+1)
if blank >3
{
break
}
continue
}
needle := "[]" ;look for []
If InStr(line, Needle, True)
{
StringReplace, line, line, [],, All
}
Txtline2 = %Txtline2%`n%line% ;combines lines together again
}
clipboard = %Txtline2%
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: Is it possible to stringreplace rtf to clipboard?

08 Mar 2018, 01:41

Well, the AHK help is your friend - have you already checked ClipBoardAll ?
itsfloody
Posts: 4
Joined: 18 Aug 2016, 22:06

Re: Is it possible to stringreplace rtf to clipboard?

08 Mar 2018, 15:57

Hey BoBo,
Thanks for the reply. Yeah tried ClipBoardAll and end up with what looks like chinese lettering

I might be able to do something with winClip...
User avatar
jeeswg
Posts: 4992
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Is it possible to stringreplace rtf to clipboard?  Topic is solved

08 Mar 2018, 21:52

This worked for me. Have WordPad open with some formatted text ready, including the word 'qwerty'.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

itsfloody
Posts: 4
Joined: 18 Aug 2016, 22:06

Re: Is it possible to stringreplace rtf to clipboard?

09 Mar 2018, 00:28

Perfect! Just what I needed. Thanks jeeswg!
burque505
Posts: 547
Joined: 22 Jan 2017, 19:37

Re: Is it possible to stringreplace rtf to clipboard?

10 Mar 2018, 17:09

Very nice indeed, jeeswg, it will be useful. Thank you!
Edit: Even more useful than I thought. If I replace

Code: [Select all] [Download] GeSHi © Codebox Plus

WinActivate, ahk_class WordPadClass

with

it works with Word for .docx and .rtf, and I wasn't sure it would.
So a little extra code and it'll work with any editor that handles .docx or .rtf, I'm hoping.
Regards,
burque505

Return to “Ask For Help”

Who is online

Users browsing this forum: bunam, Evil-e and 91 guests