If condition is unable to compare two strings

Task

New Member
Hello folks,

Currently working on storing the excel values in an array variable and comparing each and every value with another static value created in a variable. Suppose, Term 20 Plus is one of the value is present in array variable and the same value(Term 20 Plus) present in the variable which was created for a static value. Now, If I compare these two strings using a variable in IF activity it was unable to compare and it was going to else condition. Could anyone suggest, please?
 

VJR

Well-Known Member
Hi Task,

When I tried this it was rightly going into the "If" condition and not into the "else".
Maybe there is a space or some newline character in the array that is coming from the Excel.
Print that element of the array in a MessageBox by preceeding and succeeding it with some character like '*' .

eg; *$myArray(2,1)$*
If it shows *Term 20 Plus* then there is no extra character.
But if it shows a gap after the first or before the second * then there is some character due to which the strings are not matching.
Do the same thing for the value in your String variable.
 

Task

New Member
Hello VJR,

What you said is right. When I am trying to print it in message box it was showing in the format which showed below. Could you please suggest.

*Term 20 Plus
*
 

VJR

Well-Known Member
Hi Task,

It looks like there is a newline character at the end of the that text.
Probably this is already in the Excel and coming from there. So at first see if you are able to put the data in Excel without the newline. If not then the following can be done.

- Take a Value type variable call it as $NewLineCharacter$
- In the value box of its variable manager, just add a new line by pressing enter at the first position. You will see that the cursor has moved down to the next row in the box which means that a newline character has been added
- Inside the loop, just before your If Else condition, use the string Replace function to replace the $NewLineCharacter$ in your Array element with a blank string. Do not add a space. Just an empty string. Meaning you should leave the Replace box in the String operation without adding anything into it.
- Next time whenever the loop runs, the newline will be replaced with an empty character and performs the comparison.
This will happen for every element of the array irrespective of whether a newline is present in it or not.
 
Hi ,

For the better result in string comparison, Always try to use String functions, such as Trim and Compare.
Step 1: Using String function - Trim() => To Remove the while space in the start and end.
Step 2 : Now Use the String Comparison function for both the variables => It will provide if both strings are match then TRUE else False. Assign this output into another variable. ( Here you can also able to use the Match Case also.. but this is not possible in If..else..equals)
Step3: Now use IF..Else with Result variable and continue the process.
 

Attachments

  • AA_StringOperations.JPG
    AA_StringOperations.JPG
    32.9 KB · Views: 54
Top