AutoHotkey Community

It is currently May 27th, 2012, 3:54 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: August 16th, 2010, 9:36 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
I need to get only one digit from a number.
For Example
Code:
SomeVar = 200
X = the 1st digit (2) of SomeVar
Y = the 2nd digit (0) of SomeVar
Z = The 3rd digit (0) of SomeVar


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2010, 9:40 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Code:
SomeVar = 200
X := SubStr(SomeVar, 1, 1)
Y := SubStr(SomeVar, 2, 1)
Z := SubStr(SomeVar, 3, 1)

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2010, 9:47 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
I assume that changing 1 changes the number of diggits
Not that I need it, but it will be good to know, how can I get it backwords ?
200 (0, 0 and 2)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2010, 9:50 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Just flip the order of the second paramater to make it reversed:
Code:
SomeVar = 200
X := SubStr(SomeVar, 3, 1)
Y := SubStr(SomeVar, 2, 1)
Z := SubStr(SomeVar, 1, 1)

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2010, 10:28 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Another approach:
Code:
someVar := 200

stringSplit, someVar, someVar

loop % strLen( someVar )
  msgbox % ( a_index = 1 ) ? "X " X := someVar%a_index%
         : ( a_index = 2 ) ? "Y " Y := someVar%a_index%
         : ( a_index = 3 ) ? "Z " Z := someVar%a_index%
         : "" ; <- Snips and ties off the end of sausages.

msgbox % X Y Z
; and or
msgbox % someVar1 someVar2 someVar3
Single chars can also use their own array ;)

*Edit forgot to show the array elements by themselves,
added them in purple. In this case use of vars is actually redundant :mrgreen:
htms

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 17th, 2010, 1:21 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
Code:
SomeVar = 200
loop, parse,SomeVar
{
    var := Chr(a_index + (90-strlen(SomeVar)))
    %var% := "the " a_index " digit (" A_LoopField ") of SomeVar"
}
ListVars
pause

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Leef_me and 29 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