Jump to content

How do I StringReplace a value that changes?


Recommended Posts

I have an xml file with the string "/merchant/poslogin.php?key=20000209_432</url>" and my script changes the value of 20000209_432. If I need to change it again I want to search for the string "/merchant/poslogin.php?key=" and tell autoit to count 27 characters from the string and replace the next 12 digits with my inputbox value. How can I tell StringReplace to start 27 digits from the string being replaced?

$NewCustomerID = StringReplace($chars, "2000293", $CustomerID) <-- Here
    $NewCustomerPin = StringReplace($NewCustomerID, "432", $CustomerPin)
    FileOpen("tiapp.xml", 2)
    FileWrite("tiapp.xml", $NewCustomerPin)
    FileClose($xmlfile)
    Exit

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

OK that worked out good. Here is my final code:

$NewCustomerID = StringReplace($chars, 553, $CustomerID) ;Repaces the Customer ID in tiapp.xml
    $NewCustomerData = StringReplace($NewCustomerID, 562, $CustomerPin) ;NewCustomerData hold the properly modified xml data
    FileOpen("tiapp.xml", 2)
    FileWrite("tiapp.xml", $NewCustomerData)
    FileClose($xmlfile)
    Exit
Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

heres another way.

#include <String.au3>

$sString = "/merchant/poslogin.php?key=20000209_432</url>"
$sID = _StringBetween($sString,"key=","</url>")
$sNewString = StringReplace($sString,$sID[0],"newKey")
MsgBox(0,"",$sNewString)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
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
 Share

  • Recently Browsing   0 members

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