Jump to content

Recommended Posts

Posted

I'm creating an application restore process where it needs to copy an ID from a text file that has a lot of other variables. 

I was looking into FileReadToArray or FileReadLine however it looks to me that they copy the whole line instead of just the values I want. 

The text file looks something like this: 

 

<appSettings>
 <add key="ServerId" value="d438a121-i91f-4f11-4a80-a682-f6b8ea40c348" />
 <add key="LablelId" value="72617f67-5629-b158-a6c630546ad0" />
</appSettings>
 
 
I need to create an variable that will equal to the ServerID, or just d438a121-i91f-4f11-4a80-a682-f6b8ea40c348 without the quotes or any other values.
 
From there I want to call that variable to input into a text box. ( I can figure this part out on my own)
 
So I'm really looking help with how I can copy the value between the quotes on a specific line within the text file. 
Seems easy enough in my mind, but just started AutoIT and have not been able to find any thing that can help me with this. Thanks.
  • Moderators
Posted

#include <Array.au3>

$sString = '<add key="ServerId" value="d438a121-i91f-4f11-4a80-a682-f6b8ea40c348" />'
$aSplit = StringSplit($sString, '"')
    _ArrayDisplay($aSplit)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

WillTing,

local $str = _
    '  <appSettings>' & @crlf & _
    '   <add key="ServerId" value="d438a121-i91f-4f11-4a80-a682-f6b8ea40c348" />' & @crlf & _
    '   <add key="LablelId" value="72617f67-5629-b158-a6c630546ad0" />' & @crlf & _
    '  </appSettings>'

local $ServerId = stringregexpreplace($str,'(?is).*serverid" value="([^"]+)".*','\1')

ConsoleWrite($ServerId & @CRLF)

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted

Thanks for the response guys. I think this will really help me get to the next phase.

Here's how I'm going to use the array function. Because the Server and Label ID's are not constant values and they are different every time I launch the application I will have to use the "FileReadLine" function first to pull this line out. Then I'm hoping I can use the results from the FileReadLine to insert it into the Array function to perform this step. I'm going to try this out today and I will post my results. 

Posted (edited)

WillTing,

I need to create an variable that will equal to the ServerID

 

Try post #3.  It creates variable $ServerID.

 

Not sure what you mean by this:

Here's how I'm going to use the array function

 

Regarding "FileReadLine":

  1. Read the file to a variable (see Help File)
  2. Run code in topic #2 using the variable that you read the file to in place of the variable "$str"

Ther is no need to read the file line by line.

kylomas

edit: spelling

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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...