Jump to content

Recommended Posts

Posted

Has anyone seen an AutoIt script anywhere that does this?  That just has a simple inputbox one pastes text with hard returns into, then output result just gets sent to the clipboard (sort of what these online websites do:  https://www.textfixer.com/tools/remove-line-breaks.phphttps://miniwebtool.com/remove-line-breaks/https://capitalizemytitle.com/tools/remove-line-breaks/).

The inputbox is easy enough to create with the Code Wizard:

#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Width=300, Height=140
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Remove Line Breaks","Paste your block of text to clear of hard returns in the box below:",""," ","300","140","-1","-1")
Select
    Case @Error = 0 ;OK - The string returned is valid

    Case @Error = 1 ;The Cancel button was pushed

    Case @Error = 3 ;The InputBox failed to open

EndSelect
#EndRegion --- CodeWizard generated code End ---

Thank you in advance for any kind help! :)

Posted

You could simply wrap your input box with this :

Local $sText = InputBoxEx("Remove Line Breaks", "Paste your block of text to clear of hard returns", "", "", 300, 140)
ConsoleWrite($sText & @CRLF)

Func InputBoxEx($sTitle, $sPrompt, $sDefault = "", $sPwChar = "", $iWidth = -1, $iHeight = -1, $iLeft = Default, $iTop = Default, $iTimeout = 0, $hWnd = 0)
  ClipPut(StringStripWS(StringRegExpReplace(ClipGet(), "(\v)", " "), 7))
  Local $sInput = InputBox($sTitle, $sPrompt, $sDefault, $sPwChar, $iWidth, $iHeight, $iLeft, $iTop, $iTimeout, $hWnd)
  Return SetError(@error, 0, $sInput)
EndFunc

 

Posted (edited)
On 4/2/2026 at 8:01 AM, Nine said:

You could simply wrap your input box with this :

Local $sText = InputBoxEx("Remove Line Breaks", "Paste your block of text to clear of hard returns", "", "", 300, 140)
ConsoleWrite($sText & @CRLF)

Func InputBoxEx($sTitle, $sPrompt, $sDefault = "", $sPwChar = "", $iWidth = -1, $iHeight = -1, $iLeft = Default, $iTop = Default, $iTimeout = 0, $hWnd = 0)
  ClipPut(StringStripWS(StringRegExpReplace(ClipGet(), "(\v)", " "), 7))
  Local $sInput = InputBox($sTitle, $sPrompt, $sDefault, $sPwChar, $iWidth, $iHeight, $iLeft, $iTop, $iTimeout, $hWnd)
  Return SetError(@error, 0, $sInput)
EndFunc

 

Thank you!

It didn't work, however.  When I tested the websites they removed carriage returns.  But when I put it into the inputbox, seemingly nothing happened :think::think::think: ...

Here is sample text to "clean up".  Might this help?

Hey folks, welcome back to Dig DriveDIY.

Well, in today's video, we're going to

start on our next project. This time

it's here at home and it's this little

machine right here. We've got this

EasyGo RXV golf cart that maybe you saw

in a previous video I acquired from

Carts and Parts. And with the help of

them and a bunch of new parts, we're

going to kind of do this like we're

doing the Bronco, a mini version, but

we're going to strip it down to the

chassis and then clean it up and then

start to rebuild it. I'm going to enlist

the help of my girls hopefully to tackle

this. But we hope this is maybe a two or

three video series, but it's going to be

a lot of fun. I think we can't wait to

have a newer cart. So, I'm going to get

them on the line and we're going to get

going.

>> Stick dry.

>> All right. Well, in the last video, you

saw us take delivery of this cart. And

Kobe stuck around and helped me with the

first step that I wanted to do. If I was

going to get a new cart, I wanted it to

be lithium ion conversion. So, we put in

a factory easygo lithium ion conversion

and that went great. We've went out and

done a done a couple test drives and

this thing is quick and the brakes work

 

What do you think?

 

**  Just noticed something that happens occasionally.  Can the " >> " also be taken care of, by any chance?.

 

Thank you!

Edited by Diana (Cda)
Posted (edited)

I just tested the script Nine provided with the text you pasted and noticed the following.

Regarding your original post, an Input box wont do what you need. According to the InputBox help:

Quote

The string returned will not exceed 254 characters and if input contains carriage returns or linefeeds, the result will be truncated at the first occurrence of those characters.

In my opinion, if you wish to keep it simple, you could replace the InputBox with a MsgBox, and once you click Ok the data currently in your clipboard will be processed with Nine's script, particularly the ClipPut/ClipGet part.

Also, if I had the text in the clipboard previous to running the script, the Carriage Returns were removed perfectly. The problem is that in Nine's Script, this

ClipPut(StringStripWS(StringRegExpReplace(ClipGet(), "(\v)", " "), 7))

is put previous to the Input box being created and interacted with by the user, etc.,

Local $sInput = InputBox($sTitle, $sPrompt, $sDefault, $sPwChar, $iWidth, $iHeight, $iLeft, $iTop, $iTimeout, $hWnd)

You could try the following modified version.

Local $sText = InputBoxEx("Remove Line Breaks", "Paste your block of text to clear of hard returns", "", "", 300, 140)
ConsoleWrite($sText & @CRLF)

Func InputBoxEx($sTitle, $sPrompt, $sDefault = "", $sPwChar = "", $iWidth = -1, $iHeight = -1, $iLeft = Default, $iTop = Default, $iTimeout = 0, $hWnd = 0)
  Local $sInput = InputBox($sTitle, $sPrompt, $sDefault, $sPwChar, $iWidth, $iHeight, $iLeft, $iTop, $iTimeout, $hWnd)
  ClipPut(StringStripWS(StringRegExpReplace(ClipGet(), "(\v)", " "), 7))
  Return SetError(@error, 0, $sInput)
EndFunc

In this case though, the InputBox does nothing except allow you to trigger when the data in your clipboard is processed (i.e. when you click "ok" or "cancel"). (And the @error is now returned for ClipPut, instead of the InputBox).

If you really want to be able to paste your text to process it, a GUI and edit control would be what you are looking for.

As for removing ">>", you could try this modified version:

Local $sText = InputBoxEx("Remove Line Breaks", "Paste your block of text to clear of hard returns", "", "", 300, 140)
ConsoleWrite($sText & @CRLF)

Func InputBoxEx($sTitle, $sPrompt, $sDefault = "", $sPwChar = "", $iWidth = -1, $iHeight = -1, $iLeft = Default, $iTop = Default, $iTimeout = 0, $hWnd = 0)
  Local $sInput = InputBox($sTitle, $sPrompt, $sDefault, $sPwChar, $iWidth, $iHeight, $iLeft, $iTop, $iTimeout, $hWnd)
  ClipPut(StringStripWS(StringRegExpReplace(ClipGet(), "(\v|>)", " "), 7))
  Return SetError(@error, 0, $sInput)
EndFunc

Considering those are at the beginnings of paragraphs, you could replace those with Carriage returns to keep your data easier to read, depending on what you are doing with the text. But that would require a little more processing, and you mentioned they seem to be there only occasionally, so that wouldn't be very reliable I'm guessing.

And my try at it:

#include <MsgBoxConstants.au3>   

Local $iChoice = MsgBox($MB_YESNO, "Remove Line Breaks", "Would you like to clear hard returns and "">>"" from the clipboard data?")

If ($iChoice = $IDYES) Then ClipPut(StringStripWS(StringRegExpReplace(ClipGet(), "(\v|>)", " "), 7))

Hope this helps,

Best regards,

Donny

 

Edited by donnyh13

LibreOffice UDF  

Scite4AutoIt Spell-Checker Using LibreOffice

WPS Office adapter — Use MS Word UDFs with WPS Office!

LibreOffice API Inspector tools

Spoiler

"Life is chiefly made up, not of great sacrifices and wonderful achievements, but of little things. It is oftenest through the little things which seem so unworthy of notice that great good or evil is brought into our lives. It is through our failure to endure the tests that come to us in little things, that the habits are molded, the character misshaped; and when the greater tests come, they find us unready. Only by acting upon principle in the tests of daily life can we acquire power to stand firm and faithful in the most dangerous and most difficult positions."

Posted
3 hours ago, Diana (Cda) said:

But when I put it into the inputbox, seemingly nothing happened

I probably do not understand what you want to achieve with the single inputbox you provided in your OP.  Could you describe in more details the steps you expect to go through and the final result.  Maybe Donny understand better ;)

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
×
×
  • Create New...