From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Text File

Solved!
Go to solution

Hello,

 

i want to read a very big text file in LabVIEW. This file has 4 columns and every column is not the same long. I want to put every column data in a 1D array. How can I realize that in LabVIEW?

 

I will attach an example text file.

 

Best regard

0 Kudos
Message 1 of 9
(4,097 Views)

Hello TUDarmstadtLLX,

 

The example text file you provided is not use a common delimeter to seperate columns. This makes parsing the file difficult since there are varrying numbers of the space character between columns. I recommend using tabs or commas as delimeters in your text file whenevr possible. Then parsing the file into LabVIEW is trivial using the File IO functions like Read Delimited Spreadsheet.

 

Otherwise, if that is not possible. You can try using this example to parse the arbitrary number of spaces:

http://www.ni.com/example/25669/en/

 

0 Kudos
Message 2 of 9
(4,075 Views)

From your very simple txt if there will always be a character column of nothing but space, then this will work.  

Omar
0 Kudos
Message 3 of 9
(4,037 Views)

Or a simpler method. The best way would be to format your text file correctly when it is generated.

 

Text To Table.png

Ben64

 

Message 4 of 9
(4,016 Views)
Solution
Accepted by topic author TUDarmstadtLLX

I noticed I was missing the last column so attached updated VI

 

The "Search and Replace Pattern.vi" will not give you expected results if you have more than one empty column at the beginning.

Something like this.

Drehzahl Beta Alpha A3 A4
1111     1    0     4  11
2222     2    5     6  22
         2    6        33
              7        44
              8        55

The 7 and 8 will end up in the "Beta" column, not the "Alpha".

Column A4 only get 11 and 22 correct.

Omar
Message 5 of 9
(4,008 Views)

Hello Omar,

 

thanks for your reply. This is an amazing solution, which is just what I want.

 

Best regards

 

 

0 Kudos
Message 6 of 9
(3,974 Views)

Hello Omar,

 

I try to understand your logic, but I can not. Can you explain it?

 

Best regard

0 Kudos
Message 7 of 9
(3,967 Views)

I have about 75 products that I must communicate with over a RS232 "maintenance" port intended to be used by humans reading a terminal so I have a collection of tricks.

Works by looking for the col of blank space between the data (ASCII 32).

blank col.pngFirst convert the text into an array of lines.

Then convert each line into an array of [U8]

Combine into a 2D array. Shorter lines get padded with nulls (ASCII 00) on the end.

Transpose the array. Rows are now Cols and Cols are now Rows

Now go Row by Row (what was Cols) looking for rows made up of nothing but spaces (ASCII 32) and Nulls (ASCII 0). When True if you have collected Rows with stuff in them (Not an Empty [U8] Array) then Transpose the array back to a Col and then search for any NULLs (\00) to remove. Repeate.

 

Omar
Message 8 of 9
(3,936 Views)

Thanks a lot. Amazing logic!

 

Best regard

0 Kudos
Message 9 of 9
(3,931 Views)