LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading in text file

I have a text file that contains something like this:

 

<setting name="ip_address" serializeAs="String">
                <value>239.0.0.1</value>

 

I want to be able to search through the text file and based upon finding <setting name="ip_address" serializeAs="String">, I'd like to get the 239.0.0.1

 

New to Labview.  So I'm not sure how to do it.  Currently using LabView 2012.  Thanks.

0 Kudos
Message 1 of 8
(2,840 Views)

That looks a lot like XML.  You might want to look at the few XML examples in the LabVIEW Example Finder (do a search for XML in the Example Finder).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 8
(2,834 Views)

It is xml, but it doesn't have the xml extention.  From what I've seen, the .xml is required.  I'm currently using read from text file, but can't figure out how to do the search.

0 Kudos
Message 3 of 8
(2,825 Views)

@Sebastian2011 wrote:

I have a text file that contains something like this:

 

<setting name="ip_address" serializeAs="String">
                <value>239.0.0.1</value>

 

I want to be able to search through the text file and based upon finding <setting name="ip_address" serializeAs="String">, I'd like to get the 239.0.0.1

 

New to Labview.  So I'm not sure how to do it.  Currently using LabView 2012.  Thanks.


Generally, your txt file will be read in as a spreadsheet string or as an array of strings.

 

You can use Match Pattern to look for <setting name="ip_address" serializeAs="String">\r<value>

 

Three outputs will contain the text leading up to the search string, the search string, and the rest (the rest will contain the ip_address followed by the rest of the text file),

 

Use Match Pattern again looking for </value> that comes after the ip_address.  The first output will contain the ip_address.

0 Kudos
Message 4 of 8
(2,798 Views)

Thansks for the help.  When I enter <setting name="port" serializeAs="String"> it finds the string, but when I enter <setting name="port" serializeAs="String">\r<value> it does not find it.

0 Kudos
Message 5 of 8
(2,777 Views)

Copy/paste that section of text from the file into a string constant.  (I may have missed some tab characters or was incorrect in how I added the return character).

0 Kudos
Message 6 of 8
(2,770 Views)

Cool, it works. 

 

     <setting name="port" serializeAs="String">
                <value>5678</value>

 

How can I strip off the trailing </value>

0 Kudos
Message 7 of 8
(2,760 Views)

Use the same vi with </value> as the search string.  The port will be the string returned before the search results (top output)

0 Kudos
Message 8 of 8
(2,752 Views)