Jump to content

How to select specific text?


Recommended Posts

Hi, I'm new at AutoIt, and I must say that AutoIt is Amazing!

but I have only one problem.

How can I select specific text in notepad?

select from "here" to "here2" (the underlined text)

ej:

Julius Caesar is probably one of the most popular Roman military of all time. With him, casting the foundations for the future Roman Empire. But Caesar's military career would be boosted by an indisputable fact that led him to obtain great wealth and increase his personal prestige far.

"HERE"

For any Roman military to annex new territories, then the Roman Republic, led to great privileges, titles and power ... very powerful. Caesar, a military and political career with a good chance of promotion

"HERE2"

thanks and greetings!

Link to post
Share on other sites

I was looking for information on StringRegExp, and got the following code:

#Include <String.au3>
$Text = FileRead("email.txt")
$EmailFound = StringRegExp($Text, "([A-Za-z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})", 3)
If @error = 1 Then
    MsgBox(0, "E-Mail", "No E-Mail addressess found in the supplied text")
Else
    For $i = 0 To UBound($EmailFound) - 1
        MsgBox(0, "E-Mail", $EmailFound[$i])
    Next
EndIf

But this works only for e-mails... I need that works for any text

any idea?

Link to post
Share on other sites
  • Moderators

estemarito,

We expect you to do some work for yourself here. Just posting a script you found on the forum does not qualify as "work". :(

However, wnat you want is very simple. And as I have some time to spare, here is how you do what you want. Put your complete text into Notepad and run this: :)

#Include <String.au3>

; Activate Notepad
WinActivate("Untitled - Notepad")
WinWaitActive("Untitled - Notepad")

; Get the text from Notepad
$sText = ControlGetText("Untitled - Notepad", "", "[CLASS:Edit; INSTANCE:1]")
; And display it
MsgBox(0, "Notepad text", $sText)

; Set UNIQUE start and end points for your extract
$sStart = "For any "
$sEnd = " promotion."

; Extract the extract
$aExtract = _StringBetween($sText, $sStart, $sEnd)

; Add back the start and end strings
$sExtract = $sStart & $aExtract[0] & $sEnd
; And display it
MsgBox(0, "Extract", $sExtract)

; Put the extract on the clipboard
ClipPut($sExtract)

But remember, the next time you ask for help, we will expect you to have made much more effort to solve your problem by yourself first. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

Thank you very much Melba23 and Volly.

Please understand that just 2 days ago I found autoit. I know php, html and many other languages, but recently I'm starting with autoit. again, thank you very much. the script worked perfectly

sry my english, i use traductor.,..

Link to post
Share on other sites
  • 11 years later...
On 3/23/2010 at 9:33 AM, Melba23 said:

estemarito,

 

We expect you to do some work for yourself here. Just posting a script you found on the forum does not qualify as "work". :(

 

However, wnat you want is very simple. And as I have some time to spare, here is how you do what you want. Put your complete text into Notepad and run this: :)

 

#Include <String.au3>

; Activate Notepad
WinActivate("Untitled - Notepad")
WinWaitActive("Untitled - Notepad")

; Get the text from Notepad
$sText = ControlGetText("Untitled - Notepad", "", "[CLASS:Edit; INSTANCE:1]")
; And display it
MsgBox(0, "Notepad text", $sText)

; Set UNIQUE start and end points for your extract
$sStart = "For any "
$sEnd = " promotion."

; Extract the extract
$aExtract = _StringBetween($sText, $sStart, $sEnd)

; Add back the start and end strings
$sExtract = $sStart & $aExtract[0] & $sEnd
; And display it
MsgBox(0, "Extract", $sExtract)

; Put the extract on the clipboard
ClipPut($sExtract)

But remember, the next time you ask for help, we will expect you to have made much more effort to solve your problem by yourself first. :)

 

M23

I too have only discovered autoIt recently, and created a very basic script to automate 1 particular repetitive task and it works fine - but I'm very new, but excited to have found this program.

However, having browsed the form, I've seen a particular trend and similar replies whereby  experienced users here get upset with new folk asking for help, if they haven't already busted a gut trying to figure out a solution for themselves. 

Why does this forum expect new folk to reinvent the wheel, fail at the task, and then its only permisable to ask for help? 

And whilst I'm here, can I ask, I have several lines of contact info in a notepad. Name, Company, Email, Tel, Address, and want to automate to insert into a CRM program. Whilst I can handle the date paste into specified text boxes in the CRM, how would I select individual lines of info from the notepad? 

Some folks are not full time coders or professional coders but can be small business owners, trying to streamline processes, whilst handling many other aspects of their business, but the fact they have shown interest in AutoIt I felt would be enough encouragement for experienced users to maybe provide some help? 

This is just an observation, and a comment made with good intention. 

 

thanks all! 

Link to post
Share on other sites
  • Moderators

grooveman,

Quote

Why does this forum expect new folk to reinvent the wheel, fail at the task, and then its only permisable to ask for help? 

You are by no means the first to have made this comment - and the answer is always the same: The forum ethos is to help you get your code running as you wish, but also to get you to understand why so that you have a better chance of getting it right next time. Think of the old saying: "Give a man a fish, you feed him for a day; give a man a net and you feed him forever". We try to be net makers and repairers, not fishmongers.

We do not expect people to "bust a gut", but (in most cases) neither are we prepared to just "barf up code" (as one of my US colleagues puts it). There are several websites where you can pay to get code written to spec - we are a bunch of enthusiastic volunteers who want to help people along the road to becoming proficient coders by getting them to do some of the work themselves. No-one here minds (or laughs at) an amateurish, non-functioning script - all we want to see is that the poster has made some attempt to use the Help file to make a start.

I hope that you find that explanation sufficient. And thank you  for the restrained manner in which you expressed yourself above - we try to run a civilised forum and polite comments such as yours are always welcome.

And as to your questions - I am sure you can guess the answer I am about to give you: What have you tried that has not worked to your satisfaction? Which functions does the Help file suggest might be of use?  I suggest that a couple which might be include: FileRead (to get the text into a variable) and _StringBetween (to extract the required data from within the variable). Sight of a sample (suitably redacted) text would also be useful if you require further help.

Over to you!

M23

Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
  • Melba23 unlocked this topic

Additional comment on your requirement.  In case of .txt file, it is not recommended to go thru Notepad (or any other text editor) for automation.  You can easily read, write and delete lines with File* functions.  I would strongly suggest you invest your time learning those functions instead of trying to automate Notepad.  Let us know if you need help with your script if you face an issue, we will gladly be able to help assuming you provide script and data.  It is quite important that you make your script runable to us in order to get proper help. 

BTW, welcome to the forum !

Link to post
Share on other sites
On 1/29/2022 at 6:59 AM, grooveman said:

Some folks are not full time coders or professional coders but can be small business owners, trying to streamline processes, whilst handling many other aspects of their business, but the fact they have shown interest in AutoIt I felt would be enough encouragement for experienced users to maybe provide some help?

Even from business perspective, it could be better "to take some time to learn the language, and then understand for yourself what the code is doing", not just relying on uncontrolled black boxes for processes that can change over time.

Edited by robertocm
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...