 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Joso
Joined: 09 Mar 2010 Posts: 11
|
Posted: Fri Mar 12, 2010 3:09 pm Post subject: grabbing a phone number |
|
|
841 pages of questions .. if someone has already invented this wheel, I'd appreciate help finding it.
I want to send a phone number in various possible formats (eg 305-888-6160 3058886160 (305) 888-6160) to a variable. (for further use within a program)
The program would start from the cursor being located anywhere within a string of numbers, spaces and punctuation comprising a phone number.
Thanks.
Joe |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Mar 12, 2010 4:29 pm Post subject: |
|
|
highlight the text/numbers and ^c to copy it
then u can StringReplace all non-digit characters |
|
| Back to top |
|
 |
Joso
Joined: 09 Mar 2010 Posts: 11
|
Posted: Fri Mar 12, 2010 4:43 pm Post subject: |
|
|
| I want the program to highlight the phone number string for me. - I want it to figure out what's a phone number and what's not. Clearer? |
|
| Back to top |
|
 |
MacroGeek
Joined: 08 Mar 2010 Posts: 4 Location: Toronto
|
Posted: Fri Mar 12, 2010 5:06 pm Post subject: |
|
|
| Joso wrote: | | I want the program to highlight the phone number string for me. - I want it to figure out what's a phone number and what's not. Clearer? |
It's probably possible. A lot depends on the application you are selecting from, the kind of text that surrounds the telephone number, and other factors.
For example, if the telephone numbers appear in this configuration...
John 555-111-2222
Mary 444-111-2222
...and the caret (cursor) lies somewhere on the line the containing the name and number, you could do something like this:
Home ; go to start of line
Shift + End ; select to end of line
Copy to Clipboard
Copy Clipboard to a Variable
Strip out anything in the Variable that is not a number.
This approach selects the line, rather than the number, but the script figures out what is phone number and what is not. Obviously, this approach will not work if you have entries like this:
John 1 555-111-2222
John 2 666-777-8888
If you provide more details, maybe we can provide more help. |
|
| Back to top |
|
 |
Joso
Joined: 09 Mar 2010 Posts: 11
|
Posted: Fri Mar 12, 2010 5:36 pm Post subject: |
|
|
Thanks for thinking about this - I appreciate it.
The phone number could appear in a variety of formats (3058886160 305-888-6160 (305) 888-6160) sometimes within a sentence with spaces on both sides of the number and sometimes at the beginning or end of a line of text - we could rule out international numbers and numbers containing letters (1-800-CALLPAIN eg) to keep things fairly straightforward. The phone number would always consist of 10 numbers, but the length of the string containing those 10 numbers might vary depending on the format used.
I'm thinking that the logic of the program would be to examine each character moving in one direction until a character other than (123456789-(){space}) was encountered, then move back the other way using the same test - when both "ends" of the phone number were determined, the string would be highlighted and saved to the clipboard.
I'd be surprised if no one has worked out an algorithm for this sort of search previously - if not - maybe I'll have to start from scratch.
Thanks again for your thoughts. |
|
| Back to top |
|
 |
emmanuel d
Joined: 29 Jan 2009 Posts: 436 Location: Belgium
|
Posted: Fri Mar 12, 2010 6:01 pm Post subject: |
|
|
something like this?: | Code: | MsgBox,% CreateNormalPhoneNr("3058886160") ; Normal nr
MsgBox,% CreateNormalPhoneNr("305\88.86.160")
MsgBox,% CreateNormalPhoneNr("305\88-86.160")
MsgBox,% CreateNormalPhoneNr("305-888-6160")
MsgBox,% CreateNormalPhoneNr("(305) 888-6160")
return
CreateNormalPhoneNr(PhoneNr) {
StringReplace, PhoneNr, PhoneNr,-,, ALL
StringReplace, PhoneNr, PhoneNr,.,, ALL
StringReplace, PhoneNr, PhoneNr,(,, ALL
StringReplace, PhoneNr, PhoneNr,),, ALL
StringReplace, PhoneNr, PhoneNr,/,, ALL
StringReplace, PhoneNr, PhoneNr,\,, ALL
StringReplace, PhoneNr, PhoneNr,%A_Space%,, ALL
Return,%PhoneNr%
} |
_________________ Stopwatch
emdkplayer
http://www.autohotkey.com/forum/viewtopic.php?p=306819
the code i post falls under the:
WTFYW license
, wich meens its free to use
Last edited by emmanuel d on Fri Mar 12, 2010 6:06 pm; edited 3 times in total |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Mar 12, 2010 6:01 pm Post subject: |
|
|
| MacroGeek wrote: | | It's probably possible. A lot depends on the application you are selecting from ... If you provide more details, maybe we can provide more help. | This statment is important. |
|
| Back to top |
|
 |
Joso
Joined: 09 Mar 2010 Posts: 11
|
Posted: Fri Mar 12, 2010 8:54 pm Post subject: |
|
|
| emmanuel d wrote: | something like this?: | Code: | MsgBox,% CreateNormalPhoneNr("3058886160") ; Normal nr
MsgBox,% CreateNormalPhoneNr("305\88.86.160")
MsgBox,% CreateNormalPhoneNr("305\88-86.160")
MsgBox,% CreateNormalPhoneNr("305-888-6160")
MsgBox,% CreateNormalPhoneNr("(305) 888-6160")
return
CreateNormalPhoneNr(PhoneNr) {
StringReplace, PhoneNr, PhoneNr,-,, ALL
StringReplace, PhoneNr, PhoneNr,.,, ALL
StringReplace, PhoneNr, PhoneNr,(,, ALL
StringReplace, PhoneNr, PhoneNr,),, ALL
StringReplace, PhoneNr, PhoneNr,/,, ALL
StringReplace, PhoneNr, PhoneNr,\,, ALL
StringReplace, PhoneNr, PhoneNr,%A_Space%,, ALL
Return,%PhoneNr%
} |
|
Thanks - but the problem is getting the PhoneNr into the program - not stripping out the punctuation. Maybe I can do something with the LOOP function.
Joe |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
|
| Back to top |
|
 |
Murx Guest
|
Posted: Fri Mar 12, 2010 9:15 pm Post subject: |
|
|
| What about to simply extract all digits from the string using RegExMatch() ? |
|
| Back to top |
|
 |
Joso
Joined: 09 Mar 2010 Posts: 11
|
Posted: Fri Mar 12, 2010 11:47 pm Post subject: |
|
|
| sinkfaze wrote: | | Could you provide us a sample of the data you're trying to extract the phone number from? |
This a sample of (305) 888-6160 text contained in a word document or a text file or outlook journal entry or other 305-888-6160
3058886160 sort of text editing program, like myNoteskeeper which permits the user to select text by holding the shift (b)345-888-6160 ext 2543 (c)305.888.6160 and moving the cursor 3058886160. I don't think I could generalize a method to pickup strings in image files, pdf's or web pages. Thanks for any thoughts.
Joe |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 3254 Location: Simi Valley, CA
|
Posted: Sat Mar 13, 2010 3:13 am Post subject: |
|
|
| Code: | #p::
SendInput, +{end} ; select text to the right of the caret, up to the end of a line
OldClip := ClipboardAll ; save old contents
Clipboard := "" ; wipe clipboard (to work properly with clipwait)
Send ^c ; copy
ClipWait, 1 ; wait fir clipboard's contents to update (max 1-second)
If RegexMatch( Clipboard, "[(). \-\d]{10,}", phone ) ; Regex = Abracadabra
&& RegexMatch( phone := RegexReplace( phone, "\D" ), "^\d{10}$", phone ) ; nested regex = Ballalaa kazaam
MsgBox, % "Phone = (" SubStr( phone, 1, 3 ) ") " SubStr( phone, 4, 3 ) "-" SubStr( phone, 7 )
Else Clipboard := OldClip ; otherwise, restore old clip
OldClip := "" ; wipe to save space
Return |  _________________ Ternary (a ? b : c) guide TSV Table Manipulation Library
Post code inside [code][/code] tags! |
|
| Back to top |
|
 |
Joso
Joined: 09 Mar 2010 Posts: 11
|
Posted: Sat Mar 13, 2010 4:03 pm Post subject: |
|
|
; Regex = Abracadabra
wow! - This is just the sort of tool I'm looking for - now I know how I'll spend my Saturday. Thanks alot.
Joe |
|
| Back to top |
|
 |
Joso
Joined: 09 Mar 2010 Posts: 11
|
Posted: Sat Mar 13, 2010 11:58 pm Post subject: |
|
|
my oldest son told me when he was a small child that the purpose of living was "to meet new people and learn new things" - Well today I learned some new things. Thank you.
Just in case I'm not the only one in the dark, here's what I figured out your code meant:
RegexMatch( Clip, "[(). \-\d]{10,}", phone )
String, "[find arg]", output var
"[().space - any digit](at least 10 digits for a match}"
&& RegexMatch( phone := RegexReplace( phone, "\D" ), "^\d{10}$", phone ) ; nested regex = Ballalaa kazaam
AND set string "phone" = "phone" with any non-digit characters removed
find arg: "or any digit {at least 10 digits long}from the end of the string"
then format it:
FPhone := "(" SubStr( phone, 1, 3 ) ") " SubStr( phone, 4, 3 ) "-" SubStr( phone, 7, 4)
var set to ( 1st 3#s) ) next 3# - next 4#
- Thanks to this tool, I have a nifty little dialer program that will keep me from misdialing numbers all day long. It runs under windows XP, and uses the dialing function of Outlook 2003 or 2007. After I've road tested it for a week or so, if anyone's interested in the code, I'll be happy to share.
Thanks again
Joe |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|