09-06-2011 09:07 AM
I'm openning a text file in LabVIEW, and and need to parse some information from it. However, when I open the file, there are extra spaces between the letters. When I just open the same file with Notepad or Wordpad, the spaces are not there. Is there a way to eliminate this problem?
09-06-2011 09:20 AM - edited 09-06-2011 09:22 AM
The only thing that Read from Text File would do is to convert the EOL character if you have the function set up to do so. As the Help for that function describes:
The function converts all platform-dependent end-of-line characters to line feed characters unless you right-click the function and remove the checkmark next to the Convert EOL shortcut menu item. If you wire a path to file, the function opens the file before reading from it and closes it afterwards.
So, are you reading a text file that was created on another platform? If not, then provide an example of the text file you are reading and the actual LabVIEW code you are using to read the file.
Another possibility is that your text contains non-printable characters which Notepad and Wordpad convenienly hide. But they're still there.
09-06-2011 09:25 AM
It's probably a unicode file. Certain languages in Windows can't use one byte for a character, and thus need to use 2. If you end up using English (or any other that do fit in one byte, you'll see these spaces (I think they are actually null characters).
Rolf posted a library here that will do the translation back and forth.
You could also open the file in something like Notepad++ which will allow you change the encoding.
09-06-2011 09:36 AM
I've attached a sample text file that I am using. Again, if you open it with Notepad, it looks normal. However, opening it in LV the extra spaces are there.
09-06-2011 09:45 AM
As suspected by Matthew, it's a unicode file. The header for the file is FF FE. The LabVIEW functions do not handle unicode files. Use the library that Matthew pointed to.
09-06-2011 09:53 AM - edited 09-06-2011 09:54 AM
And, since after the \FF\FE, every other character is \00, you can even do a homebrew quick&dirty solution.
Are the files always like that, or are some "normal"?
09-06-2011 09:54 AM
Was this text created with a Labview program, or some instrument?
09-06-2011 10:11 AM
It was created in another program....not LabVIEW
04-18-2018 06:27 AM
ugh thank you for this, saved my absolute bacon, I was wasting time manually solving each problem because I didn't know the U8 converter could do that, or even what it did at all if i'm being honest.