Jump to content

Reformatting a string not to contain any line breaks?


nf67
 Share

Recommended Posts

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 by nf67
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...