Sign in to follow this  
Followers 0
IanN1990

Int to String

2 posts in this topic

Hi, 

I am trying to convert the following code into AutoIt.

http://stackoverflow.com/questions/35821224/is-there-a-simple-way-to-convert-a-unique-string-of-characters-into-a-unique-num

I have seceded in the first part (admittedly the $variables need to be tided up) but i cant figure out how to turn it back into a string :(

 

#include "array.au3"
#include "string.au3"

$test = "A6HJ92B"
$testlen = StringLen($test)
$test = StringSplit($test, "")
Local $Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "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"]

local $newCode
For $i = 1 to UBound($test)-1
   $ArrayFound = _ArraySearch($Array, $test[$i], 0, 0, 3)
   If $testlen= $i Then
       $newCode += $ArrayFound
   Else
       $newCode += $ArrayFound*(36^($testlen-$i))
   EndIf
Next

ConsoleWrite(String($newCode))

http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#toString() has not helped much.

Just wondering if anyone else had an idea to this?

Share this post


Link to post
Share on other sites



Hi!

Your Script converting a string to a number runs fine!

All you have to do converting a number to a Base35-String is the reverse way....

#include "array.au3"
#include "string.au3"

$test = "A6HJ92B"
$testlen = StringLen($test)
$test = StringSplit($test, "")
Local $Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "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"]

Local $newCode
For $i = 1 To UBound($test) - 1
    $ArrayFound = _ArraySearch($Array, $test[$i], 0, 0, 3)
    If $testlen = $i Then
        $newCode += $ArrayFound
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ArrayFound = ' & $ArrayFound & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    Else
        $newCode += $ArrayFound * (36 ^ ($testlen - $i))
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ArrayFound = ' & $ArrayFound & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    EndIf
Next

ConsoleWrite(String($newCode) & @CRLF)

$string = ""

For $j = 7 To 0 Step -1                                 ;maximum 7 chars 0-9A-Z
    For $i = 36 To 1 Step -1             ;all chars
      If $newCode - $i * (36 ^ $j) >= 0 Then
            $newCode = $newCode - $i * (36 ^ $j)
            $string &= $Array[$i]                       ;add char
            ExitLoop
        EndIf
    Next
Next
MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '$string' & @CRLF & @CRLF & 'Return:' & @CRLF & $string) ;### Debug MSGBOX

 

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