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: 

saved file doesn%27t match original text

Solved!
Go to solution

Using LV 2010.  I have an application where I'm encrypting a file and saving it to the hard drive as a text file.  The problem I'm having is that the string of characters that I'm writing to the file does not match the string of characters that are read from the file.  The files match for the first 10 characters, then in the original string, there is a \r character that is dropped from the file.  The rest of the file doesn't match too well after that.  Also, the size of the strings are different too by a few thousand characters.  Is there some setting in the file read or write that could be causing this?  Thanks.

 

0 Kudos
Message 1 of 18
(2,884 Views)
Solution
Accepted by topic author rickford66

Right-click your Read/Write to Text File functions and uncheck 'Convert EOL'.  Or use the Read/Write Binary functions.

0 Kudos
Message 2 of 18
(2,876 Views)

I've done that already.  Also, I think I had the issue reversed.  It's the original text that does not have the \r in it, but the text read from the file does.  That is really weird.

0 Kudos
Message 3 of 18
(2,872 Views)

Upon closer examination, it appears that whenever the original encrypted file contains either a \r or a \n, the write to the file automatically changes them to \r\n in every case.  I wonder if there's a way to stop this.

0 Kudos
Message 4 of 18
(2,870 Views)

@rickford66 wrote:

It's the original text that does not have the \r in it, but the text read from the file does


Are you inspecting the raw file or are you reading it back using LabVIEW?

 

(If you are using LabVIEW for reading, you of course need to disable convert EOL here too, or use the binary file IO).

 

You typically get much better help if you include a simplified version of your code. 😄

0 Kudos
Message 5 of 18
(2,849 Views)

String to U8 array and write read binary as Darin suggested (he is often correct;)


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 18
(2,848 Views)

@JÞB wrote:

String to U8 array and write read binary as Darin suggested (he is often correct;)


You can wire strings directly to the binary file IO functions. No need to convert to U8.

Message 7 of 18
(2,844 Views)

I have convert EOL unchecked on all reads and writes.  Right now, I'm down to creating a string, writing it to a file, reading it back from the same file, and comparing it to the original.  If I can get a moment, I'll try to make up a small .vi that demonstrates the behavior.

0 Kudos
Message 8 of 18
(2,839 Views)

Here's a quick example (LabVIEW 2010). Result is always true in my limited testing.

 

Here's the string IO version:

 

 

(It is a bit more complicated when using the binary file IO:

(1) wire false to prepend array or string size when writing.

(2) wire -1 to count when reading.

This code is not attached, just a picture)

 

 

0 Kudos
Message 9 of 18
(2,822 Views)

Augh, I found one of my read/writes that still had the convert EOL checked.  How embarrassing.  I went through them twice and didn't see it.  Apparently I have to check things 3 times.  Thanks everyone.  Sorry about that.

0 Kudos
Message 10 of 18
(2,809 Views)