Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

When I compare two strings that look exactly the same, why does SilkTest believe they are different?

When I compare two strings that look exactly the same, why does SilkTest believe they are different?

This is a common issue that arises. Although both strings appear the same, there may be leading or trailing whitespaces that are causing the comparison to fail.

We can use any of Trim functions to remove these whitespaces.

LTrim = Strips leading whitespace from a string.
RTrim = Strips trailing whitespace from a string.
Trim = Strips leading and trailing whitespace from a string.

[-] testcase WhiteSpaces() appstate none
    [ ] 
    [ ] STRING sText1 = "HELLO WORLD"
    [ ] STRING sText2 = "HELLO WORLD "
    [ ] 
    [-] if(sText1 == sText2)    // This will not find the two strings a match
        [ ] Print("STRINGS ARE A MATCH")  
    [-] else
        [ ] Print("STRINGS ARE DIFFERENT")   
    [ ] 
    [ ] sText1 = Trim(sText1)
    [ ] sText2 = Trim(sText2)
    [ ] 
    [-] if(sText1 == sText2)    // This will find the two strings a match
        [ ] Print("STRINGS ARE A MATCH")  
    [-] else
        [ ] Print("STRINGS ARE DIFFERENT")   
    [ ] 

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:16
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.