LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read from a text file one character at a time?

Hello
I wish to read from a text file in a for loop and that on every iteration i read one charachter and proceed to the next one.
can anyone help me?
Lavi 
0 Kudos
Message 1 of 9
(4,971 Views)
Hi Lavi,

you did not say which LabView version you are using...

In the file functions palette  you find functions to read text files. One parameter is the number of chars to read. You also have to handle the read position - this differs in the different LabView versions.

But: (depending on your filesize) it should be much more efficient to read the whole file and use substring function to get one char after the other. It's also more efficient to use math functions on arrays instead of using a for loop and handle each byte separately!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(4,965 Views)
Hi GerdW

How do ou read a text file one character at a time INCLUDING whitespace characters, tabs, LF, CR, etc.  Using substrings skips all of that stuff ...

I would like to be able to read EVERY character, not just substrings...

I know I can do it by converting to byte array, but would prefer to avoid that ..

Can it be done from simple text vi's?
0 Kudos
Message 3 of 9
(4,796 Views)

Read From Text String does read every character and using substrings does not skip anything.

The only thing Read From Text File does is convert EOL if you have selected that mode.

0 Kudos
Message 4 of 9
(4,790 Views)
Yeah,  I was doing something wrong. I now see every character.

Thanks for the EOL tip - I didn't realize that was an option.


Question: How can I check to see if a charcter's ascii value is less than a 0x20 (Space character) ie: identify all acharacters that are not visible alpha-num text?

Thanks!


0 Kudos
Message 5 of 9
(4,785 Views)
Use either the Printable? (on string palette) or the less than function.
 


Message Edited by Dennis Knutson on 06-06-2008 09:54 AM
Message 6 of 9
(4,781 Views)
Just to clarify, the Printable VI is in the Comparison palette.
Eli S.
National Instruments
Applications Engineer
0 Kudos
Message 7 of 9
(4,744 Views)
Thanks Eli,

I didn't realize we could view as a hex number.

I'm up and running now - Thanks guys!

- Rick

0 Kudos
Message 8 of 9
(4,724 Views)


lava wrote:
I wish to read from a text file in a for loop and that on every iteration i read one charachter and proceed to the next one.
can anyone help me?

Some additional comments:
You really don't want to read any file one character at a time, because it is highly inefficient. More typically, you read the entire file into memory with one operation (or at least a large chunk, if the file is gigantic) and then do the rest of the operations in memory.  One easy way to analyze it one byte at a time would be to use "string to byte array" and then autoindex into a FOR loop, for example.
 
Of course you could also read the file directly as a U8 array instead of a string.


Message Edited by altenbach on 06-10-2008 08:57 AM
0 Kudos
Message 9 of 9
(4,714 Views)