LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to compare two strings and mark differences

hello all,

    I need to compare two strings and mark the differences like the attachment. Str 1 maybe not as long as str 2.

    Any suggestion?

    Thanks.

 

 

 

----
czhen
Win 10 & LabVIEW 2014 SP1
0 Kudos
Message 1 of 7
(5,221 Views)

Post the vi you have done so far. We will correct your mistakes if any and provide you the right path so that you can do it your way and will learn much faster.

 

Mathan 🙂

0 Kudos
Message 2 of 7
(5,211 Views)

Hi,

  

 I have attached a VI which might solve your purpose.Smiley Happy

 

Regards,

Gopal

Message 3 of 7
(5,188 Views)

That will not work if you have more than one character difference in the first lines of string 2. As if the first line of string2 is 123456ab890. In that case you can't use the same offset on string1 and string2.

 

Ben64

0 Kudos
Message 4 of 7
(5,153 Views)

This problem is not well defined. 

 

You said the strings can be of different lenghts, in that case are all the extra characters appended at the end as in the front panel picture you attached? Then, the first five lines are of the same lenght and the differences are one character replaced by another one (in line 1 the 7 was replaced by the letter "a", line 2 the 9 was replaced by the letter "u"). Again is it always the case?

 

If not there can be a lot of possibilities and this problem can become very complex, you need to put some boundaries somewhere.

 

Ben64 

0 Kudos
Message 5 of 7
(5,146 Views)

ben64 已写:

This problem is not well defined. 

 

You said the strings can be of different lenghts, in that case are all the extra characters appended at the end as in the front panel picture you attached? Then, the first five lines are of the same lenght and the differences are one character replaced by another one (in line 1 the 7 was replaced by the letter "a", line 2 the 9 was replaced by the letter "u"). Again is it always the case?

 

If not there can be a lot of possibilities and this problem can become very complex, you need to put some boundaries somewhere.

 

Ben64 


yea, maybe a lot of possibilities and very complex.

In my case, str 1 & str 2 come from windows command line -- FC(file compare). FC gives differences between two similar test logs.

I will try to:

1. compare the line number of two strings, and find the extra lines of str 2(more lines).

2. delete extra lines from str 2, result in str 3.

3. compare str 3 to str 1 as  Gopal's Spot Difference.vi.

I will post the solution later.

Many thanks to ben64, Gopal & all.

 

 

 

 

----
czhen
Win 10 & LabVIEW 2014 SP1
0 Kudos
Message 6 of 7
(5,088 Views)

If some lines are similar,it is too complex to sync the lines. It is not a complete solotion. But it solves my problems.

see attachment below.

 

----
czhen
Win 10 & LabVIEW 2014 SP1
Message 7 of 7
(5,063 Views)