AutoHotkey Community

It is currently May 27th, 2012, 5:33 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: grabbing a phone number
PostPosted: March 12th, 2010, 4:09 pm 
Offline

Joined: March 9th, 2010, 7:33 pm
Posts: 11
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 5:29 pm 
highlight the text/numbers and ^c to copy it
then u can StringReplace all non-digit characters


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 5:43 pm 
Offline

Joined: March 9th, 2010, 7:33 pm
Posts: 11
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 6:06 pm 
Offline

Joined: March 8th, 2010, 11:44 am
Posts: 4
Location: Toronto
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 6:36 pm 
Offline

Joined: March 9th, 2010, 7:33 pm
Posts: 11
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 7:01 pm 
Offline

Joined: January 29th, 2009, 9:50 pm
Posts: 483
Location: Belgium
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
the code i post falls under the: WTFYW-WTFPL license


Last edited by emmanuel d on March 12th, 2010, 7:06 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 7:01 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 9:54 pm 
Offline

Joined: March 9th, 2010, 7:33 pm
Posts: 11
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 10:11 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
Could you provide us a sample of the data you're trying to extract the phone number from?

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 10:15 pm 
What about to simply extract all digits from the string using RegExMatch() ?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 13th, 2010, 12:47 am 
Offline

Joined: March 9th, 2010, 7:33 pm
Posts: 11
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 13th, 2010, 4:13 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 13th, 2010, 5:03 pm 
Offline

Joined: March 9th, 2010, 7:33 pm
Posts: 11
; 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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 12:58 am 
Offline

Joined: March 9th, 2010, 7:33 pm
Posts: 11
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: dra, HotkeyStick, rbrtryn, XstatyK and 64 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group