LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading Text Files and storing in Array

I have a text file ( as attached) with 8 lines of string data. I want to read this file and store it in 1D array so i can index any line as per requirement. How can I do so?
0 Kudos
Message 1 of 13
(4,079 Views)
Read in the text (as a long string). Then feed a while-
loop with this string and search for EOL-characters.
This way you can split up your string into several
shorter strings. If you output them in your while-loop
(with indexing enabled) you get an array of strings.

Best regards
Gerd
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(4,079 Views)
Or you can use Spreadsheet String to Array...
0 Kudos
Message 3 of 13
(4,079 Views)
Read in the whole file (Read characters from File.vi), and use "spreadsheet string to array.vi" from the string functions. Rember to use the correct delimiter, it seems like the data file used Tab, so default should be fine. The result will be a 2D array of strings.

Joe
0 Kudos
Message 4 of 13
(4,079 Views)
DO you mean something like in the attached example?

Simply save your data file as C:\text.txt
and try it out..

I didn't make it pretty... ;o)

-JLV-
Message 5 of 13
(4,079 Views)
OOps... I forgot the Close file vi in the example...
Message 6 of 13
(4,079 Views)
The simplest way to do it is as follows:

Step 1: Open the file.
Step 2: Enter into a while loop.
Step 3: With each loop iteration, read a single
line of the file using the File Read vi,
with the Line Mode set to TRUE. This will
automatically read in a single line at a
time.
Step 4: Stop the loop on a File Read error. This
means that we hit the end of the file.
Step 5: Output the string array (which we have
created by auto-indexing the string output
from File Read).
Step 6: Close the file.

See the example enclosed. Cheers.

- Jim Cavera
0 Kudos
Message 7 of 13
(4,079 Views)
I'm sure Shakes didn;t expect this thread to be so popular...

;o)
Message 8 of 13
(4,079 Views)
Dear shakes,

here lies easy & soluble solution. I am attaching a vi which solves your purpose.

Your feedbacks are welcome.

Best Regards,
Nirmal
0 Kudos
Message 9 of 13
(4,080 Views)
Absolutely. Thank you guys for helping me out here. Thats why i so love this forum that i spend every spare minute online. Thaks to all here who have tried to help me :)I hope to look for your continuing support in future.

Adios
Abe
0 Kudos
Message 10 of 13
(4,079 Views)