SysCompareText class – text comparison with white spaces.

Text comparison in Dynamics AX is very easy and is provided by the == operator and the strcmp() method. The difference between these two is that == is case insensitive whereas strcmp() is case sensitive.

Let us suppose we have a case where we need to compare two strings

Text1=’A new string’;
Text2=’A new string’;

Now logically these two strings are same semantically if not for the extra white spaces. So how can we compare them? This is where the SysCompareText class can be helpful.

The static run() method takes a parameter _suppressWhiteSpaces which can control if white spaces within string should be taken into account while comparing strings. A value of true which by the way is the default value for this will ensure that white spaces are not considered while comparing. So text1 & Text2 are shown as identical. A value of false will show that Text1 & Text2 in the above case are not equal.

You can download the code for this from here.


Popular posts from this blog

How to add empty ranges in query

Get selected records in Dynamics AX 2012

How to refer to form controls in code without setting the AutoDeclaration property in Dynamics AX?