Jump to content

Recommended Posts

Posted

Hi. Lets say I got 2 scripts, is it possible to make script1 reverse a string in script2?

I tried something like this:

#include 


_WinAPI_FileReverse(@ScriptDir & "\test.txt", @ScriptDir & "\kk.txt")
ShellExecute(@ScriptDir & "\kk.txt")

Func _WinAPI_FileReverse($sFile, $sNewFile) ;coded by UEZ build 2012-10-04
If Not FileExists($sFile) Then Return SetError(1, 0, 0)
Local $iFileSize = FileGetSize($sFile)
If $iFileSize > 4294967296 Then Return SetError(2, 0, 0) ; 4294967296 = 2^32
If $sNewFile = "" Then Return SetError(3, 0, 0)
Local $hFile= _WinAPI_CreateFile($sFile, 2, 2, 2), $iBytes, $p, $bNewData
If Not $hFile Then Return SetError(4, 0, 0)
Local $tBuffer = DllStructCreate("byte[" & $iFileSize & "]")
Local $tBuffer_new = DllStructCreate("byte[" & $iFileSize & "]")
_WinAPI_SetFilePointer($hFile, 0, $FILE_BEGIN)
_WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $iFileSize, $iBytes)
_WinAPI_CloseHandle($hFile)
Local $bData = DllStructGetData($tBuffer, 1)
For $p = $iFileSize To 1 Step - 1
$bNewData &= Hex(BinaryMid($bData, $p, 1), 2)
Next
DllStructSetData($tBuffer_new, 1, Binary("0x" & $bNewData))
$hFile = _WinAPI_CreateFile($sNewFile, 1, 4, 4)
If Not $hFile Then Return SetError(5, 0, 0)
_WinAPI_WriteFile($hFile, DllStructGetPtr($tBuffer_new), $iFileSize, $iBytes)
_WinAPI_CloseHandle($hFile)
$tBuffer = 0
$tBuffer_new = 0
Return 1
EndFunc

but that will reverse the whole file, I only want to reverse a string in the file

Posted

There is _StringReverse, but I'm not following your overall request. Where is the string displayed? GUI? Text file?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Your test1.au3 is wrong. I would suggest reading the help file about FileOpen, FileRead and FileClose and then come back here if you have problems. Also the question remains why do you want to reverse an Au3 file?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

You have to load the file, find the string, reverse the string and finally write it to a file or display it.

Maybe something like this here:

#include <String.au3>
;~ $String = FileRead(@scriptdir & "2.au3")
$String = '$test = "this is a test"' & @CRLF & "$test2 = 'next line'"

MsgBox(0, "Test", SearchNReverse($String, "this is a test"))

Func SearchNReverse($sInput, $sSearch)
    Local $iPos = StringInStr($sInput, $sSearch)
    If Not $iPos Then Return SetError(0, 0, "")
    Local $sResult = StringReplace($sInput, $sSearch,  _StringReverse(StringMid($sInput, $iPos, StringLen($sSearch))))
    Return $sResult
EndFunc

Br,

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...