LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparaison between 2 strings

Solved!
Go to solution

Good afternoon,

I have a question about the comparition between 2 strings.

My VI write in a txt file a message to indicate the state of the test. If this state is unchange I don't want to write on this file that's why I test the message and the message write in the last line of the txt file to be sure they are not similar and write.

But the comparator tools I use don't give the expected solution.

Someone could explain me how compaire these 2 strings?

 

ThanksComparaison de 2 chaines.PNG

0 Kudos
Message 1 of 15
(3,026 Views)

@fxblabview wrote:

 

But the comparator tools I use don't give the expected solution.

 


  • Attach code instead of pictures
  • Look for differences in hidden characters (e.g. CR, vs LF, vs CRLF).
  • If the result is not as expected, you need to tell us what you expect!
0 Kudos
Message 2 of 15
(3,024 Views)

To detect successive duplicate messages, use a feedback node and compare current and previous.

0 Kudos
Message 3 of 15
(3,006 Views)

@fxblabview wrote:

Good afternoon,

I have a question about the comparition between 2 strings.

My VI write in a txt file a message to indicate the state of the test. If this state is unchange I don't want to write on this file that's why I test the message and the message write in the last line of the txt file to be sure they are not similar and write.

But the comparator tools I use don't give the expected solution.

Someone could explain me how compaire these 2 strings?

 

ThanksComparaison de 2 chaines.PNG


You send the strings with CR as your EOL but your read is set to convert EOL.  In Windows, EOL is CR + LF, so the changes the EOL and the strings no longer match.  It's only a guess (but a good one) since you didn't supply real code, and the probes and stuff don't show the backslash codes.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 15
(2,990 Views)
Solution
Accepted by topic author fxblabview

Since you only really care about the "readable" string content perhaps you could use the Trim Whitespace node on both before comparing them?

Message 5 of 15
(2,960 Views)

Right the txt file replace my CR by an EOL. Thats why I should put a supplementary character on the reading to have complete sentence.

Thanks for your help.

0 Kudos
Message 6 of 15
(2,947 Views)

It's a good solution to not be bored by these invisible types.

0 Kudos
Message 7 of 15
(2,944 Views)

Hi fx,

 

It's a good solution

The better solution would be to store the previous message in a feedback node for comparison: ne need to read the file before writing to it! (As has been suggested before!)

 

Simple like this:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 15
(2,941 Views)

Sorry Knight to my approximations about my first post on the forum.

My expected response was that the comparator tools give a false response when the 2 sentences tested were similar... and a true when they were different.

0 Kudos
Message 9 of 15
(2,938 Views)

Hi fx,

 

My expected response was that the comparator tools give a false response when the 2 sentences tested were similar... and a true when they were different.

The "unequal?" comparison gives TRUE when the inputs are unequal (aka "not the same").

When you are talking about this "unequal?" comparison then your expectation was right. 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 15
(2,935 Views)