Adrian Lach
Adrian Lach

Reputation: 23

Whitespaces on the right side dont matter when comparing


DEFINE VARIABLE a AS CHARACTER NO-UNDO.
DEFINE VARIABLE b AS CHARACTER NO-UNDO.
a = "123".
b = "123 ".

MESSAGE a = b
VIEW-AS ALERT-BOX.

MESSAGE LENGTH(a) = LENGTH(b)
VIEW-AS ALERT-BOX.

Does anyone know, why the first equals returns true? Are whitespaces ignored on the right side? Because a whitespace on the left would cause the equals to be false. It also doesn't matter how many whitespaces there are on the right side.

Thank you all

Upvotes: 1

Views: 105

Answers (2)

Stefan Drissen
Stefan Drissen

Reputation: 3379

https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/eq-or-=-operator.html

The equal comparison ignores trailing blanks. Thus, "abc" is equal to "abc ". However, leading and embedded blanks are treated as characters and " abc" is not equal to "abc".

Upvotes: 3

Mike Fechner
Mike Fechner

Reputation: 7192

Well, that's just the way the ABL is implemented.

You can use the COMPARE function.

MESSAGE a = b SKIP 
        COMPARE (a, "EQ", b, "RAW")
VIEW-AS ALERT-BOX.

Upvotes: 2

Related Questions