| View previous topic :: View next topic |
| Author |
Message |
Bad Juju
Joined: 19 Feb 2009 Posts: 11 Location: Southern California
|
Posted: Fri Apr 03, 2009 4:41 pm Post subject: Remove digits from a number |
|
|
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 |
|
 |
aCkRiTe
Joined: 21 Jul 2006 Posts: 555
|
Posted: Fri Apr 03, 2009 4:44 pm Post subject: |
|
|
| Code: |
Num = 800800022348
StringTrimLeft, Num, Num, 3
MsgBox, %Num%
|
_________________
HTH...
|
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Fri Apr 03, 2009 4:52 pm Post subject: |
|
|
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 |
|
 |
aCkRiTe
Joined: 21 Jul 2006 Posts: 555
|
Posted: Fri Apr 03, 2009 5:06 pm Post subject: |
|
|
| 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 |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Fri Apr 03, 2009 5:25 pm Post subject: |
|
|
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 |
|
 |
aCkRiTe
Joined: 21 Jul 2006 Posts: 555
|
Posted: Fri Apr 03, 2009 5:41 pm Post subject: |
|
|
| 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 |
|
 |
Bad Juju
Joined: 19 Feb 2009 Posts: 11 Location: Southern California
|
Posted: Fri Apr 03, 2009 5:43 pm Post subject: |
|
|
Outstanding! That worked wonderfully. Thank you very much! _________________ - Shaun |
|
| Back to top |
|
 |
|