AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Remove digits from a number

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Bad Juju



Joined: 19 Feb 2009
Posts: 11
Location: Southern California

PostPosted: Fri Apr 03, 2009 4:41 pm    Post subject: Remove digits from a number Reply with quote

I have a number that is 12 digits long (eg. 800800022348). I need AHK to remove the first three digits so that I am left with a 9 digit number (eg. 800022348). I suppose I can just subtract 800000000000 but is there another way to accomplish this?

Thanks,
Shaun
_________________
- Shaun
Back to top
View user's profile Send private message
aCkRiTe



Joined: 21 Jul 2006
Posts: 555

PostPosted: Fri Apr 03, 2009 4:44 pm    Post subject: Reply with quote

Code:

Num = 800800022348
StringTrimLeft, Num, Num, 3
MsgBox, %Num%

_________________

HTH...
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Fri Apr 03, 2009 4:52 pm    Post subject: Reply with quote

Not as readable but shorter and faster:

Code:
Num = 800800022348
Num:=SubStr(Num,4)
MsgBox, %Num%


Changed the 3 to a 4 in the SubStr function.
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.


Last edited by sinkfaze on Fri Apr 03, 2009 5:27 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
aCkRiTe



Joined: 21 Jul 2006
Posts: 555

PostPosted: Fri Apr 03, 2009 5:06 pm    Post subject: Reply with quote

sinkfaze wrote:
Not as readable but shorter and faster:

Code:
Num = 800800022348
Num:=SubStr(Num,3)
MsgBox, %Num%


Needs to be:

Code:
Num = 800800022348
Num:=SubStr(Num,4)
MsgBox, %Num%


and its not any faster...
_________________

HTH...
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Fri Apr 03, 2009 5:25 pm    Post subject: Reply with quote

You are correct about my mistake, but SubStr does perform faster than StringTrimLeft, even if the increase in speed doesn't make a significant difference in this instance.
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
aCkRiTe



Joined: 21 Jul 2006
Posts: 555

PostPosted: Fri Apr 03, 2009 5:41 pm    Post subject: Reply with quote

sinkfaze wrote:
SubStr does perform faster than StringTrimLeft, even if the increase in speed doesn't make a significant difference in this instance.


That I am not sure about, but I dont doubt that you are correct. When I said it wasnt faster, I was referring to this instance.

Code:
StartTime := A_TickCount
Num = 800800022348
StringTrimLeft, Num, Num, 3
ElapsedTime := (A_TickCount - StartTime)/1000
MsgBox, %Num% - %ElapsedTime%


and

Code:

StartTime := A_TickCount
Num = 800800022348
Num:=SubStr(Num,4)
ElapsedTime := (A_TickCount - StartTime)/1000
MsgBox, %Num% - %ElapsedTime%


I get an elapsed time of 0 in both cases.
_________________

HTH...
Back to top
View user's profile Send private message
Bad Juju



Joined: 19 Feb 2009
Posts: 11
Location: Southern California

PostPosted: Fri Apr 03, 2009 5:43 pm    Post subject: Reply with quote

Outstanding! That worked wonderfully. Thank you very much!
_________________
- Shaun
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group