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.

Comments

Popular posts from this blog

How to add empty ranges in query

The field with ID '0' does not exist in table - Cause and resolution.

Get selected records in Dynamics AX 2012