AutoHotkey Community

It is currently May 27th, 2012, 12:59 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: October 13th, 2011, 4:36 am 
Offline

Joined: October 6th, 2011, 2:03 pm
Posts: 36
Hi, I've been looking the forum for help with many scripts. I signed up recently and this my first question.

I've made a simple CLIPBOARD SCRIPT, I know there are a lot of them but I have made one that fits my simple needs.

This simple script works:

Code:
#c::
Send ^c
ClipWait, 1
TEXT= %A_YYYY%-%A_MM%-%A_DD%`n%A_Hour%:%A_Min%`n%Clipboard%`n`n
FileAppend, %TEXT%, C:/Ico/History.txt
Return

#v::
Run,C:/Ico/History.txt,,max
Return


I just need one thing to improve it. I need to check if the Clipboard is a nine digit number in order to add the text "TELEPHONE: " before the number.

There are another two possibities. If the clipboard is 4 digits and 3 letters, for example: 1234ABC, I need to add "PLATE: " before the string.

If the clipboard is 8 digits and one letter: 12345678A, I need to add "PERSON: " before the string.

So the script would look something like this (some parts missing):

Code:
#c::
Send ^c
ClipWait, 1

;   If Clipboard is 9 digits
;   ADD:= "TELEPHONE: "
;   If Clipboard is 4 digits and 3 letters
;   ADD:= "PLATE: "
;   If Clipboard is 8 digits and one letter
;   ADD:= "PERSON: "
;   If Clipboard is none of the above the variable ADD is empty

TEXT= %A_YYYY%-%A_MM%-%A_DD%`n%A_Hour%:%A_Min%`n%ADD%%Clipboard%`n`n
FileAppend, %TEXT%, C:/Ico/History.txt
Return

#v::
Run,C:/Ico/History.txt,,max
Return


I think I should use RegExMatch for this but I just don't manage it yet. Please help. Thanks a lot.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2011, 4:42 am 
Offline

Joined: February 17th, 2008, 8:52 pm
Posts: 314
I don't know regex but you could use

If var is interger
If var is alum

And

you could use StringLen verify number of digits.

If you have a whole paragraph in you clipboard then you will need to use regex.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2011, 8:16 am 
Offline

Joined: February 16th, 2010, 8:01 am
Posts: 800
Location: SciTE
I thought it would be fun to learn a little RegEx myself tonight so I used your request as an excuse to do it. Maybe this will help you.

Code:
MyClipboard = 7777AAA ; Changed for testing purposes.


If (StrLen(MyClipboard) = 9) ; If the string length is 9 do the operation
{
MyClipboard := RegExReplace(MyClipboard, "\d\d\d\d\d\d\d\d\d", "Telephone: " MyClipboard) ; 9 \d which each represent a single digit.
GoSub, ShowProduct
}

If (StrLen(MyClipboard) = 9) ; If the string length is 9 do the operation
{
MyClipboard := RegExReplace(MyClipboard, "\d\d\d\d\d\d\d\d.", "PERSON: " MyClipboard) ; . is any single digit character
GoSub, ShowProduct
}

If (StrLen(MyClipboard) = 7) ; If the string length is 7 do the operation
{
MyClipboard := RegExReplace(MyClipboard, "\d\d\d\d...", "PLATE: " MyClipboard) ; . is any single digit character
GoSub, ShowProduct
}

ShowProduct:
MsgBox % MyClipboard


Key note: These are not going to match correctly if the characters/digits are not in the same order that you listed in your request.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2011, 8:28 am 
Offline

Joined: August 7th, 2011, 1:23 pm
Posts: 754
or, in a more compact form
Code:
if (regexmatch(clipboard, "^\d{9}$"))
   clipboard := "TELEPHONE: " clipboard
else if (regexmatch(clipboard, "^\d{4}[a-zA-Z]{3}$"))
   clipboard := "PLATE: " clipboard
else if (regexmatch(clipboard, "^\d{8}[a-zA-Z]$"))
   clipboard := "PERSON: " clipboard
msgbox % clipboard


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2011, 12:12 am 
Offline

Joined: October 6th, 2011, 2:03 pm
Posts: 36
Thanks guys, it works great!


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, chaosad, Google Feedfetcher, Yahoo [Bot] and 16 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