Sign in to follow this  
Followers 0
E1M1

Is there shorter and better way to write this?

7 posts in this topic

#1 ·  Posted (edited)

Is there any better way to write this? I wanna declare 0-9 a-z A-Z

Dim $var[12]
$var[0] = 0
$var[0] = 1
$var[0] = 2
$var[0] = 3
$var[0] = 4
$var[0] = 5
$var[0] = 6
$var[0] = 7
$var[0] = 8
$var[0] = 9
$var[0] = "a"
$var[0] = "b"
Edited by E1M1

edited

Share this post


Link to post
Share on other sites



Something like this?

global $lower[26]=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
global $upper[26]=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
global $number[10]=["0","1","2","3","4","5","6","7","8","9"]

Or if you want to generate those automatically, referencing the help page "ASCII Characters"

global $lower[26]
global $upper[26]
global $number[10]

;ASCII Character Codes

For $i = 0 to 25
    $lower[$i]=Chr(97+$i)
Next

For $i = 0 to 25
    $upper[$i]=Chr(65+$i)

Next

For $i = 0 to 9
    $number[$i]=Chr(48+$i)

Next

_ArrayDisplay($lower)
_ArrayDisplay($upper)
_ArrayDisplay($number)

Share this post


Link to post
Share on other sites

Or, in a single array with only one loop:

#include <Array.au3>

Global $var[62]

For $n = 0 To 25
    If $n < 10 Then $var[$n] = Chr(48 + $n)
    $var[10 + $n] = Chr(97 + $n)
    $var[36 + $n] = Chr(65 + $n)
Next

_ArrayDisplay($var, "$var")

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Shorter, but perhaps slower:

global $lower=StringSplit('abcdefghijklmnopqrstuvwxyz','',2) 
global $upper=StringSplit('ABCDEFGHIJKLMNOPQRSTUVWXYZ','',2)
global $number=StringSplit('0123456789','',2)


(The signature is placed on the back of this page to not disturb the flow of the thread.)

Share this post


Link to post
Share on other sites

Shorter, but perhaps slower:

global $lower=StringSplit('abcdefghijklmnopqrstuvwxyz','',2) 
global $upper=StringSplit('ABCDEFGHIJKLMNOPQRSTUVWXYZ','',2)
global $number=StringSplit('0123456789','',2)

If it's not going to be called a billion times in a tight loop, then the shortest is probably the best :)

Share this post


Link to post
Share on other sites

For those that care:

ProcessSetPriority(@AutoItPID,4)
sleep(2000)
$timer1=TimerInit()
global $lower=StringSplit('abcdefghijklmnopqrstuvwxyz','',2) 
global $upper=StringSplit('ABCDEFGHIJKLMNOPQRSTUVWXYZ','',2)
global $number=StringSplit('0123456789','',2)
dbg(Timerdiff($timer1))
;--------
global $lower
global $upper
global $number
$timer1=TimerInit()
global $lower[26]
global $upper[26]
global $number[10]
For $i = 0 to 25
    $lower[$i]=Chr(97+$i)
Next
For $i = 0 to 25
    $upper[$i]=Chr(65+$i)
Next
For $i = 0 to 9
    $number[$i]=Chr(48+$i)
Next
dbg(Timerdiff($timer1))
;----------
global $lower
global $upper
global $number
$timer1=TimerInit()
global $lower[26]
global $upper[26]
global $number[10]

For $i = 0 to 9
    $lower[$i]=Chr(97+$i)
    $upper[$i]=Chr(65+$i)
    $number[$i]=Chr(48+$i)
Next
For $i = 10 to 25
    $upper[$i]=Chr(65+$i)
    $lower[$i]=Chr(97+$i)
Next
dbg(Timerdiff($timer1))
;-----------
global $lower
global $upper
global $number
$timer1=TimerInit()
global $lower[26]=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
global $upper[26]=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
global $number[10]=["0","1","2","3","4","5","6","7","8","9"]
dbg(Timerdiff($timer1))
;---------
$timer1=TimerInit()
Global $var[62]
For $n = 0 To 25
    If $n < 10 Then $var[$n] = Chr(48 + $n)
    $var[10 + $n] = Chr(97 + $n)
    $var[36 + $n] = Chr(65 + $n)
Next
dbg(Timerdiff($timer1))

Func dbg($msg)
    DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg)
EndFunc   ;==>dbg

with the results:

5.35570861659792

0.699809612674237

0.670476275616035

0.302273054256896

0.802336609820522

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0