Jump to content

How can I make autoit copy and paste only numbers.


Recommended Posts

I'm trying to make Autoit paste phone numbers into a texting program but some of the phone numbers have labels like "123-555-2838 mom" instead of "123-555-2838". 

can I make autoit completely ignore the words when copying and pasting?

 

Also how can I make autoit stop doing a repeated function when it reaches the end of the page? Or the end of a section. 

Basically if the bot notices that it isn't copying anything anymore, it should stop. is there a command for that? Or if it sees that the area below a selected area isn't white. 

 

Sorry if this doesn't make sense. I'm pretty new to coding in general and just wanted to try it out. 

Link to comment
Share on other sites

welcome HanselGarvey,

For your first quest, here is one way, Considering the recipient is always to the right of the string

$string = "123-555-2838 mom"
If Not Number(StringRight($string, 1)) Then ;checks if the rightmost character of the string is a number
    Do
        $string = StringTrimRight($string, 1)
    Until Number(StringRight($string, 1))
EndIf
MsgBox(0, "", $string)

Manipulating a whole list :

#include <Array.au3>

$sFile = @DesktopDir & "\PhoneBook.txt"
$aFile = FileReadToArray($sFile)
For $i = 0 To UBound($aFile) - 1
    If Not Number(StringRight($aFile[$i], 1)) Then ;checks if the rightmost character of the string is a number
        $string = $aFile[$i]
        Do
            $string = StringTrimRight($string, 1)
        Until Number(StringRight($string, 1)) Or @error
        $aFile[$i] = $string
    EndIf
Next

_ArrayDisplay($aFile)

Or even strip everything except numbers :

#include <Array.au3>

$sFile = @DesktopDir & "\PhoneBook.txt"
$aFile = FileReadToArray($sFile)
For $i = 0 To UBound($aFile) - 1
    $aFile[$i] = StringRegExpReplace($aFile[$i], "\D", "") ;https://www.autoitscript.com/forum/topic/145381-text-remove-all-but-numbers/?do=findComment&comment=1328591
Next

_ArrayDisplay($aFile)

 

Edited by Deye
Link to comment
Share on other sites

If your number only ever has a space between number and text (name), then you could do a simple StringSplit on that space.

$string = StringSplit("123-555-2838 mom")

$number = $string[1]

That will always return the first (or only) portion of the array regardless.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

5 hours ago, TheSaint said:

$string = StringSplit("123-555-2838 mom")

HanselGarvey,
TheSaint is getting old. o:)  Please forgive him. Of course the correct instruction is

$string = StringSplit("123-555-2838 mom", " ")

:)

BTW another way could be a regular expression

$s = "some text_123-555-2838other text"

; get the part which contains only digits and/or hyphens
Msgbox(0,"regex", StringRegExpReplace($s, '.*?([\d-]+).*', "$1") )

 

Link to comment
Share on other sites

Hi.

Some german telephon numbers are written like: +49(0)40/1234 345-765 with or without spaces. I did not find out how to deal with the spaces ("\h" works not for me) so I decided to kill all spaces.

$s = "some text+49(0)40/1234 345-765other text"
$s = StringReplace($s, " ", "")
Msgbox(0,"regex", StringRegExpReplace($s, '.*?([\d-/\+\(\)]+).*', "$1") )

Regards, Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

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

Link to comment
Share on other sites

8 hours ago, mikell said:

HanselGarvey,
TheSaint is getting old. o:)  Please forgive him. Of course the correct instruction is

$string = StringSplit("123-555-2838 mom", " ")

:)

Gawd. What a dumb moment .... and I use that function all the time ... Doh! :wacko:

And I generally always tack a '1' on the end, whether I need it or not.

$string = StringSplit("123-555-2838 mom", " ", 1)

Anyway, i like to give newbies a challenge. :lol:

P.S. All my wrestling with SQL functions yesterday, for the first time, must have dulled my normal keen edge (at least I ended up with a nice INItoSQL converter in the end). That and playing around with my new RAM Disk program development.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

If you want the literal, only numbers, maybe this:

$string = "123-555-2838 mom"

msgbox(0, '' , stringregexpreplace($string , "[^\d]" , ""))

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Wow you guys replied fast. I thought i'd get an email or something. 

 

Thanks for the help everyone. It looks like I have a lot of options. How can I use this string to copy something from a document, but I need it to be copied. 

 

It's a task that needs to be done daily like 100 times so that's why we are trying to automate it. 

 

The steps are. 

copy some text on an SQL Query (Usually something like "123 555 4567 mom" Paste it into a text messaging service (123 555 4567) and then go back to the document, copy the name and time of the appointment and do something type out. *name*, we would like to confirm your appointment on *Date*.

I can make the second part happen kinda slowly if I want. but the numbers being alone when pasted is the important part. 

I'm not sure how to get the numbers from the query into the Autoit string without actually making autoit edit itself, paste onto another program and then copy and paste this into the texting service.

 

Sorry if this is super simple. I'm legitimately a beginner here. 

Edit: I figured it out. Thank you guys so much!

Edited by HanselGarvey
Figured it out
Link to comment
Share on other sites

If you are not utilizing either the SQL UDF nor the SMS UDF (or neither), then you may have optimizations you have not considered. And as a bonus the UDF threads  are filled with a metric shit ton of solutions and enhancements.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...