LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Remove string from txt file

Solved!
Go to solution

I have a .txt file (See attached) I am using the spreadsheet to array function to extract the data that I need. I am trying to extract the Inspection Finished Time and the double number beside that seperately but I am having trouble with the delimiter. The .txt file will not always be this size but the 1st and last line will be the same 

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 1 of 20
(3,000 Views)

@PauldePaor wrote:

I have a .txt file (See attached) I am using the spreadsheet to array function to extract the data that I need. I am trying to extract the Inspection Finished Time and the double number beside that seperately but I am having trouble with the delimiter. The .txt file will not always be this size but the 1st and last line will be the same 


I'm guessing you are trying to use a blank space as the delimiter, correct?  Why not just use a more distinguishable delimiter?  A common one is CSV (comma seperated value).  If you want one more easily human-readable text file, try using a tab character.  Etc. This would at least remove any delimiting issues.

 

Would you mind posting the code you have tried so far?  That way we can give you some advice on how to tweak your approach to meet the desired solution.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 2 of 20
(2,993 Views)

I tried using the Inspection Finished as my dilimiter but it did not work. Please see mt code so far attached

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 3 of 20
(2,986 Views)

@PauldePaor wrote:

I have a .txt file (See attached) I am using the spreadsheet to array function to extract the data that I need. I am trying to extract the Inspection Finished Time and the double number beside that seperately but I am having trouble with the delimiter. The .txt file will not always be this size but the 1st and last line will be the same 


I think i would use the "Read from Text File" and select "Read Lines" from the right-click menu instead.  Then parse the info out the way you want to.

 

[edit]

Sorry, my post was made after you posted your snippet.  It seems the format is rigid and you don't have to rely on delimiters.

[/edit]

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 20
(2,976 Views)

@PauldePaor wrote:

I tried using the Inspection Finished as my dilimiter but it did not work. Please see mt code so far attached


Ah I see.  I now understand why you are having troubles.

 

You have misunderstood the term "delimiter".  In this case, a "delimiter" is the character used to seperate each and every unit of your file.  For example, this is your file using a comma delimiter:

 

12:19:26,Inspection Started (View)
12:20:29,85.80 m,Mode Changed to Inspect
12:20:33,89.96 m,Inspection Finished

 

Notice how every element that I want seperated is delimited with a comma between them.  What you are telling this function is "every item in this file is seperated by the string 'Inspection Finished'".  In other words, instead of using the comma (as in the above example), you are using "Inspection Finished".  This will be very chaotic and would look something like this:

 

12:19:26Inspection FinishedInspection Started (View)
12:20:29Inspection Finished85.80 mInspection FinishedMode Changed to Inspect
12:20:33Inspection Finished9.96 m

 

You are trying to use the delimit as a "search".  When the delimiter is really a seperation character that partitions the file into smaller segments.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 5 of 20
(2,971 Views)

How can I now only get the time and double by inspection finished? 

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 6 of 20
(2,960 Views)

@PauldePaor wrote:

How can I now only get the time and double by inspection finished? 


You know where each piece of data starts and ends in the string.  That's one way you could do it.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 20
(2,956 Views)

@PauldePaor wrote:

How can I now only get the time and double by inspection finished? 


There are a few ways to approach this depending on what exactly your end goal is. 

 

Do you want them both in one string?  "12:20:33 89.96 m"

 

Do you want them both as seperate strings (also perhaps in an array)?   "12:20:33"  "89.96 m"

 

Do you want the time as a string and the value as a number?  "12:20:33"  89.96

 

Etc.

 

EDIT:

 

Also do you ideally want to specify a line number and extract this info?  Or do you want to parse every single line after the top "title" style line?  These are things that can be considered as well.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 8 of 20
(2,949 Views)

I would like them in an array both of them can be strings it does not matter for my application. The text I want will always be on the last line of the file

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 9 of 20
(2,932 Views)

Example_VI.png

0 Kudos
Message 10 of 20
(2,925 Views)