Question

This is my first ever post on Stackoverflow! any help would be much appreciated.

Im an AutoIT beginner and trying to create a script that takes a string, converts it to ASCII and saves it in an array using StringToASCIIArray

What i would like to achieve is that, i need the output to be printed in a text file, so i can copy it for later use.

Ive tried using ConsoleWrite Function, the characters get printed just as i expect them to be, however it would nice if someone could point me out in the right direction to have them printed in a new text file or something. Thanks!

Here's the code:

#include <MsgBoxConstants.au3>
#include <Array.au3> 

Test()

Func Test()
; Convert the string to an ASCII array.
Local $aArray = StringToASCIIArray("Hi, this is a new string")
Local $sizeArr = UBound($aArray)

For $i = 0 to $sizeArr - 1
    ConsoleWrite("Chr(" & $aArray[$i] & ")" & " & ")    ; need this output     in a new variable?
Next

;Run("notepad.exe")
;WinWaitActive("Untitled - Notepad")
;Send($aNewArray)
EndFunc   

Update I managed to do it by creating a console application that takes an input string, converts the input to ascii and displays the formated output on the console. I can simply copy the output from there on....Not the best solution though, but it works :)

Code::

#include <MsgBoxConstants.au3>
#include <Array.au3>

myexample()

Func myexample()

 Local $sInput
 While True
    $sInput &= ConsoleRead()
    If @error Then ExitLoop
    Sleep(25)
WEnd

Local $aArray = StringToASCIIArray($sInput)     ; store string to array
 Local $sizeArr = UBound($aArray)       ; Get array size

For $i = 0 to $sizeArr - 1               ;For each element of array Do:
ConsoleWrite("Chr(" & $aArray[$i] & ")" & " & ") ;write to console ascii in Chr() 
Next

EndFunc
Was it helpful?

Solution 2

Hello ist this what you want?

;~ string = example string :: output = Chr(101) & Chr(120) & Chr(97) & Chr(109) & Chr(112) & Chr(108) & Chr(101) & Chr(32) & Chr(115) & Chr(116) & Chr(114) & Chr(105) & Chr(110) & Chr(103)

Global $re = Test('example string')
ConsoleWrite($re & @CRLF)
FileWrite(@ScriptDir & '\output.txt', $re)
ShellExecute(@ScriptDir & '\output.txt')

Func Test($str)
    ; Convert the string to an ASCII array.
    Local $aArray = StringToASCIIArray($str)
    Local $s = ''

    For $i = 0 To UBound($aArray) - 1
;~      ConsoleWrite("Chr(" & $aArray[$i] & ")" & " & ") ; need this output     in a new variable?
        $s &= "Chr(" & $aArray[$i] & ") & "
    Next
    $s = StringTrimRight($s, 3) ; delete the last "blank & blank"
    Return $s
EndFunc   ;==>Test

OTHER TIPS

Just use _FileWriteFromArray to get your file.

Why do you put the string in an array at all? Convert it and just use FileWrite

For $i = 0 to $sizeArr - 1
    ConsoleWrite("Chr(" & $aArray[$i] & ")" & " & ")
    FileWrite("test.txt", $aArray[$i] & @CRLF)
Next
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top