Jump to content

Recommended Posts

Posted

I wan't to make script that searcesh for

"minItemLvl = " and then replaces number after =. Only proplem is minItemLvl = 91 might be on diferent position (depends on file). Also number after = isn't always same.

How do I write function that searches for "minItemLvl = " and then replaces numberafter that? StringReplace Requires given string but I don't know what that number could be I know only that there is number after = but I don't know it's value.

Here's what I got while I was trying to find solution myself.

#Include <FileListToArray3.au3>
$FileList = _FileListToArray3(@scriptdir, "*", 1, 1,  1)
;~ minItemLvl = 91
for $i = 1 to 3
    $data =  FileRead($FileList[$i])
    $pos = StringInStr($data,"minItemLvl = ")
Next

edited

Posted (edited)

What are you trying to replace the number with? That's important info in order to come up with a working solution. And your code as posted isn't going to work at all so we will be starting from scratch here.

EDIT: Also, does that line only appear once in each file or does it occur more than once?

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted (edited)

I am trying to replace that number with number I want 10 for example.

Edit: I need to replace it only once in file.

I came up with this code:

#Include <FileListToArray3.au3>
$FileList = _FileListToArray3(@scriptdir, "*", 1, 1,  1)
;~ minItemLvl = 101
$files = ""
for $i = 1 to $FileList[0]
    $data =  FileRead($FileList[$i])
FileDelete($FileList[$i])
    FileWrite($FileList[$i],StringRegExpReplace($data,"minItemLvl = \d","minItemLvl = 10",1))
    ShellExecute($FileList[$i])
Next

But now 91 turned to 101 not 10

Edited by E1M1

edited

Posted (edited)

For $i = 1 To Ubound($fileList) -1
    $sStr = FileRead($filelist[$i])
    $sStr = StringRegExpReplace($sStr, "(?i)(minitem.+=)\s*\d+", "$1 " & $i, 1);; Here I'm just replacing it with $i but you can substitute your own method for determining the number
    If @Extended Then
        $hFile = FileOpen($filelist[$i], 2)
        Filewrite($hFile, $sStr)
        FileClose($hFile)
    EndIf
Next

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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
×
×
  • Create New...