Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #295 String to Enum

Given the enumerated type T, create a function TryStrToEnum that takes a string s as input and converts it into an enum value of type T.

Explain whether the conversion is case sensitive or not.
Explain what happens if the conversion fails.

X : T := T'Value (S);

Case-insensitive conversion of trimmed string S to enumeration type T. Constraint_Error is raised otherwise.

New implementation...
< >
Bart