Close popover
Thomas Sasnett (ThomasSasnett)
Lead Robotics Architect u2013 Pega Consulting
Pegasystems Inc.
ThomasSasnett Member since 2016 10 posts
Posted: March 31, 2021
Last activity: March 31, 2021

Comparing Strings with Pega Robotics

There have been a few posts lately asking about comparing strings. While this is arguably a simple topic, I thought I would make a quick post to show the various ways you might do so.

1. The suggested and easiest way is to use the Equals method from the StringUtils component. This has a parameter that allows you to ignore casing and even culture (if comparing strings from two different culture settings).

2. An alternative way would be to use a boolean expression. To do this, add a boolean expression to your automation. In the expression field, enter your expression (I like to use A==B for comparisons) where A and B are the inputs; although these are arbitrary and you can rename them however you see fit). You then need to make sure the expression understands that these are strings. You can do this by editing the Identifiers collection in the properties window, or by clicking the hyperlink labelled "Identifiers - String" at the bottom of the properties window (which changes all identifiers to strings at once).

3. A third way would be to use a more advanced boolean expression. This would be a C# expression that you might use to perform multiple operations. For my example, I have used; A.Trim().ToUpper()==B.Trim().ToUpper() as my expression. This would require the same steps as above, however this expression will remove leading and trailing spaces from the string as well as convert both to uppercase so that casing of either string is irrelevant.

4. Another option would be to use a script component. This would be overkill for comparing strings and I would not suggest it solely for that purpose.


When troubleshooting why either of these methods are not returning the results you expect, the RuntimeLog can be helpful. Usually when things don't match it is because of casing or because of extra spaces in the text. Check out the attached sample solution for some examples.

***Edited by Moderator Marissa to add the Developer Knowledge Share tag***
Pega Robotic Desktop Automation 19.1 Pega Robotic Process Automation 19.1 Robotic Process Automation Cross-Industry Robotics System Architect Developer Knowledge Share