Start a new topic

Dictionary "Else"

Is there a way to have a default or Else case for a dictionary?

if no matches are found the input is output, is there a way to say "if nothing matches, output X"

Another way to say it would be "for everything else, output X"

I can do it through the wonderful API interface now but it would be cleaner through a dictionary.


It is possible. However, to do that would mean essentially creating a regex entry that tests for all of your other entries in that dictionary as well. It wouldn't be very clean and would need to be updated if you added other entries to the dictionary. The API in this case is a cleaner solution.
Sounds good.

In that vein, is there a way to tell in the API if a dictionary failed to match anything? Or do I just need to test if the output from ApplyDictionary is the same as the input?
Testing if its the same is probably the best way. You can encapsulate all of this logic in a virtual field function placed in the Globalcode class and then it can be easily reused from profile to profile.
One of the things I was trying to do with the dictionary was figure out if a string was a title or not (trying to parse a larger field from a web form). What I ended up doing was to make a dictionary that matches all of the known titles to -BLANK-. Then, when I run the string against the dictionary it will either return "" for a match or anything else for a non-match.

Currently I am working out how I will assign appeals which is based on a complicated cascade of if statements. It would be nice to be able to test against a dictionary and get a positive confirmation of a non-match. There is the possibility of a case where the source code that would match an appeal would actually be the appeal itself. So I would end up thinking that there wasn't a match with the before and after comparison, when in fact there was, it just didn't change anything. I'll try to avoid that possibility procedurally but unfortunately I am not always in control of the naming of codes.
Login or Signup to post a comment