Jump to content

How do I compare data in a text/xml file and modify it?


Recommended Posts

I have a string in an xml file:

<url>/merchant/poslogin.php?key=20000209_432</url>

The 20000209 and 432 are like user names and passwords. I want my script to read this data from the xml when it starts and if it is the original generic string then I want the program to prompt the user to add a new user name and password. If it isn't the generic user name and password then I want the program to ignore it. Basically the user will only need to enter their user name and password once and from that point on, there will be no more need for this part of the program. I can change the string to say anything by default if that helps auto it identify that part of the script.

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

  • Moderators

computergroove,

Read the file with FileRead and see if the string "merchant/poslogin.php?key=20000209_432" (or the essential part of it) exists - StringInStr will do that for you.

If the string does not exist then carry on. If it does exist, then use 2 InputBoxes to get the new values, insert them in the file text using StringReplace and finally rewrite the file with FileWrite.

That should be enough to get you started. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

OK I'm stuck. Here's what I have so far:

$xmlfile = FileOpen("tiapp.xml", 0)

; Check if file opened for reading OK
If $xmlfile = -1 Then
    MsgBox(0, "Error", "Unable to open file")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($xmlfile) ;reads the xml file and adds it to $chars
    $result = StringInStr($chars, "20000209_432")
    MsgBox(0, "Search result:", $result)
    FileClose($xmlfile)
Wend

The above creates a msgbox that returns a value of 553. I was expecting it to return 20000209_432. What am I doing wrong?

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 I'm stuck. Here's what I have so far:

$xmlfile = FileOpen("tiapp.xml", 0)

; Check if file opened for reading OK
If $xmlfile = -1 Then
    MsgBox(0, "Error", "Unable to open file")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($xmlfile) ;reads the xml file and adds it to $chars
    $result = StringInStr($chars, "20000209_432")
    MsgBox(0, "Search result:", $result)
    FileClose($xmlfile)
Wend

The above creates a msgbox that returns a value of 553. I was expecting it to return 20000209_432. What am I doing wrong?

553 means that StringInStr counted 553 characters from the beginning of the string to the point where 20000209_432 was found. You can use this value to remove unwanted characters from the beginning of the string with the function StringTrimLeft (trimming the left side of the string). Edited by Manadar
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...