Cancel
Showing results for 
Search instead for 
Did you mean: 

Compare strings

Creator
Creator

Hi!

I'm having problem comparing two strings.

Untitled.jpg

The code above shows what I'm trying to do. The problem is that the "if" statement is never true, not even when Machine := "Slitt" and Name := "Slitt".

The variable Name takes the "handwritten" string "Slitt" as its value, while the variable Machine takes the value "Slitt", which is importet as an argument from an excel file. Might this be the problem and in such case, how can I solve it?

2 REPLIES

Re: Compare strings

Siemens Phenom Siemens Phenom
Siemens Phenom

I do not understand what you are trying to achieve with the statement strRCopy(@.Machine,strlen(@.Machine)), because it will just return the whole string @.Machine.

 

I can think of two things that might go wrong in your case:

  1. If the string contains additional whitespace, for example a trailing space character, the operator = will compute false. You can use the function trim to delete leading and trailing whitespace.
  2. If the two strings have mismatching upper-case/lower-case characters, the operator = will compute false. You can use the operator /= instead to ignore the character case.

I suggest that you set a breakpoint before the if-statement. Then execute the method, so that the debugger will being opened. Look at the "Variables" tab at the bottom of the window and compare the value of the local variables 'Machine' and 'Name'.

_________________________________________________________________
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: Compare strings

Creator
Creator

I was just trying to solve the problem by using the function strRcopy, but as you said, it doesn't do the trick! However, the trim function was great and solves my problem. Thanks for the quick answer.