LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read in a text file character by character and keep the numbers (0-9), the decimal point(.) and +- ?

Hi


I was wondering h ow to read in a text file with a x line header (default 16 lines) followed by 2 columns of data character by character, keeping the numbers 0-9 (2 columns of data), the decimal point (.) and +- ?

Thank you.
0 Kudos
Message 1 of 6
(3,024 Views)
First read everything as one long string, then chop it up later.

There are many ways to do this, e.g. use "scan strings for tokens" to get the position of the 16th linefeed, then feed the rest through "spreadheet string to array".

I don't quite understand what you mean to keep the numerical characters, decimal points and signs. Do you want to keep them as ASCII characters or do you want to convert them to numeric data types (e.g. DBL or I32).

Why don't you attach a sample text file and tell us what you want. It is always easier to have an example.
0 Kudos
Message 2 of 6
(3,017 Views)


@altenbach wrote:
First read everything as one long string, then chop it up later.

There are many ways to do this, e.g. use "scan strings for tokens" to get the position of the 16th linefeed, then feed the rest through "spreadheet string to array".

I don't quite understand what you mean to keep the numerical characters, decimal points and signs. Do you want to keep them as ASCII characters or do you want to convert them to numeric data types (e.g. DBL or I32).

Why don't you attach a sample text file and tell us what you want. It is always easier to have an example.





Yes, I want to keep them as Ascii characters. Some of these files have a mixture of tabs,commas,dashes or whatever as delimeters. Eventually I want to read a file with a X line header followed by two columns of data with a tab as the delimeter to perform some calculations with it.

I have attached an example file.

Thank you.
0 Kudos
Message 3 of 6
(3,016 Views)
Here is a method to remove/replace all characters except the one you selected, using the Search & Replace Pattern string function.
CC
Chilly Charly    (aka CC)
Message 4 of 6
(3,012 Views)

OK, if this is really a MS Word document, it will be a little more complicated. A word document is in a proprietary format and contains a lot of other information not relevant to your problem (open it in notepad to see ;)).

You will not easily be able to read a word document with the simple file IO Vis and make sense of the data.

Some possible solutions:

  • I am not familar with it, but the NI LabVIEW Report Generation Toolkit for Microsoft Office might help.
  • You might be able to use some of the OLE methods similar to the example "Write Table To XL.vi" that ships with LabVIEW. Again, I cannot help you with that.

    I would just copy the text in word and paste it into notepad, the save it as plain text file. It will be much easier to handle without all that extra baggage.
0 Kudos
Message 5 of 6
(3,009 Views)
Easier with an example string. Here is a modified version which skip all the CR LF before the first numeric instance. But of course, you still have to read the file, as discussed by altenbach 😉

CC
Chilly Charly    (aka CC)
Message 6 of 6
(2,999 Views)