Jump to content
Sign in to follow this  
russell

Help converting letters to number

Recommended Posts

russell

I was woundering how i would set this up: I a a varibale that has letters and numbers, the lenght of the variable can change. I was wanting to convert the letters to a number so it is all numbers. I'm pretty sure ill have to make it a string but then im kinda lost.

$var='A7601000aFBFBEFB33528985'
LettersToNumbers()
;===============================================================================
Func LettersToNumbers()
If $var = 'A' Then $var = 1
If $var = 'B' Then $var = 2
If $var = 'C' Then $var = 3
If $var = 'D' Then $var = 4
If $var = 'E' Then $var = 5
If $var = 'F' Then $var = 6
If $var = 'G' Then $var = 7
If $var = 'H' Then $var = 8
If $var = 'I' Then $var = 9
If $var = 'J' Then $var = 10
If $var = 'K' Then $var = 11
If $var = 'L' Then $var = 12
If $var = 'M' Then $var = 13
If $var = 'N' Then $var = 14
If $var = 'O' Then $var = 15
If $var = 'P' Then $var = 16
If $var = 'Q' Then $var = 17
If $var = 'R' Then $var = 18
If $var = 'S' Then $var = 19
If $var = 'T' Then $var = 20
If $var = 'U' Then $var = 21
If $var = 'V' Then $var = 22
If $var = 'W' Then $var = 23
If $var = 'X' Then $var = 24
If $var = 'Y' Then $var = 25
If $var = 'Z' Then $var = 26
MsgBox  (0,'',$var)
EndFunc
;===============================================================================

muppet hands are so soft :)

Share this post


Link to post
Share on other sites
russell

update of progress

#include <String.au3>
#include <Array.au3>
$var='A7601000aFBFBEFB33528985'

Local $array1 = _StringExplode($var, "", 0)
_ArrayDisplay($array1, "StringExplode 0")

LettersToNumbers()
MsgBox  (0,'',$var)
;===============================================================================
Func LettersToNumbers()
If $var = 'A' Then $var = 1
If $var = 'B' Then $var = 2
If $var = 'C' Then $var = 3
If $var = 'D' Then $var = 4
If $var = 'E' Then $var = 5
If $var = 'F' Then $var = 6
If $var = 'G' Then $var = 7
If $var = 'H' Then $var = 8
If $var = 'I' Then $var = 9
If $var = 'J' Then $var = 10
If $var = 'K' Then $var = 11
If $var = 'L' Then $var = 12
If $var = 'M' Then $var = 13
If $var = 'N' Then $var = 14
If $var = 'O' Then $var = 15
If $var = 'P' Then $var = 16
If $var = 'Q' Then $var = 17
If $var = 'R' Then $var = 18
If $var = 'S' Then $var = 19
If $var = 'T' Then $var = 20
If $var = 'U' Then $var = 21
If $var = 'V' Then $var = 22
If $var = 'W' Then $var = 23
If $var = 'X' Then $var = 24
If $var = 'Y' Then $var = 25
If $var = 'Z' Then $var = 26
EndFunc
;===============================================================================

muppet hands are so soft :)

Share this post


Link to post
Share on other sites
Melba23

russell,

What you want to do is extremely easy. StringMid will look at each of the charcters in turn - use StringLen to get the count. Then Asc (look in the Helpfile for details) will be of great help - all you need to do is check that the returned value is within the A-Z range and then subtract 64. To get it all into a string just create an empty string before you loop through the characters and append each one (either raw on converted) using &= as you deal with it. ;)

But could I ask why you want to do this? The process is essentially irreversible as there is no way to determine which of the numbers in the final are actually numbers and which are converted letters. :huh:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
UEZ

Here the code which M23 described above more or less.

$var='A7601000aFBFBEFB33528985'

MsgBox(0, "Test", LettersToNumbers($var))

Func LettersToNumbers($sString)
    If Not StringLen($sString) Then Return SetError(1, 0, 0)
    Local $aChars = StringSplit($sString, "", 2), $i, $sNumber, $s
    For $i = 0 To UBound($aChars) - 1
        $s = Asc(StringUpper($aChars[$i])) - 64
        Switch $s
            Case 1 To 26
                $sNumber &= $s
            Case Else
                $sNumber &= $aChars[$i]
        EndSwitch
    Next
    Return $sNumber
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
russell

UEZ thankyou, i shall study and try to master this. Melba23 thankyou for the guidance where to start my skills. Im using this to make a unique computer id, that string of numbers is bits of data from CPU,hdd etc. Thankyou both so much


muppet hands are so soft :)

Share this post


Link to post
Share on other sites
Melba23

russell,

Rather than reinvent the wheel, you might like to look at this UDF from guinness. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
PhoenixXL

Here is another implementation

#include <BackRef.au3>

$var = 'A7601000aFBFBEFB33528985'
MsgBox(64, "Return:", GlobalBackRef($var, '(.*?)([A-Za-z])(.*)', 'RetNum'))

Func RetNum($s_Match)
Return Asc(StringUpper($s_Match)) - 64
EndFunc   ;==>RetNum


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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  

×