nf67 Posted November 20, 2012 Posted November 20, 2012 (edited) Evening,I've been copying a lot of text from PDF files and other documents. Problem is, this text appears badly mangled when pasted again, causing formatting issues. I've been trying to write a script that would automatically reformat the copied string:#include #include #NoTrayIcon Opt("TrayMenuMode", 1) $AboutTrayItem = TrayCreateItem("About") TrayCreateItem("") $ExitTrayItem = TrayCreateItem("Exit") TraySetState() $hDLL = DllOpen("user32.dll") Beep(1100,300) While 1 While _IsPressed("11",$hDLL) If _IsPressed("43",$hDLL) Then ClipPut(StringStripWS(StringReplace(StringReplace(_ClipBoard_GetData(),@lf," "),@cr," "),4)) Beep(1300,150) While _IsPressed("43",$hDLL) Sleep(250) WEnd EndIf WEnd Local $msg = TrayGetMsg() Select Case $msg = $AboutTrayItem MsgBox(64, "About", "When CTRL+C is pressed, a reformatted version of the string that has thereby been copied, without any newline characters, should be placed on the clipboard.") Case $msg = $ExitTrayItem ExitLoop EndSelect WEnd DllClose($hDLL) Beep(600,300)So far, it's working for some of my sources. Others, like this two-column book, I still can't nicely copy from.How do I get out all line breaks, newlines, carriage returns etc. out of a string?Thanks in advance! Edited November 20, 2012 by nf67
dany Posted November 20, 2012 Posted November 20, 2012 Do you just want to remove everything or do you want to replace it with something uniform? Either way, you can do this with StringRegExpReplace: $sString = StringRegExpReplace($sString, '[rnt]+', ' ') ; Replace line feed, carriage return or tab with a space. [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF
nf67 Posted November 21, 2012 Author Posted November 21, 2012 Thanks, went with this in the end: ClipPut(StringStripWS(StringRegExpReplace(_ClipBoard_GetData(), '[rnt]+', ' '),4)) Apparently the timing was also an issue, putting the beep (or a sleep) before the string modification helped.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now