12-01-2016 10:49 AM
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
Solved! Go to Solution.
12-01-2016 11:23 AM
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/
12-01-2016 01:05 PM
From your very simple txt if there will always be a character column of nothing but space, then this will work.
12-01-2016 04:15 PM
12-01-2016 05:17 PM
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.
12-02-2016 04:50 AM
Hello Omar,
thanks for your reply. This is an amazing solution, which is just what I want.
Best regards
12-02-2016 05:20 AM
Hello Omar,
I try to understand your logic, but I can not. Can you explain it?
Best regard
12-02-2016 07:46 AM
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).
First 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.
12-02-2016 08:11 AM
Thanks a lot. Amazing logic!
Best regard