[Lazarus] Easiest way to "case" strings
Michael Van Canneyt
michael at freepascal.org
Sat Mar 21 15:57:41 CET 2009
On Sat, 21 Mar 2009, Lee Jenkins wrote:
> Vincent Snijders wrote:
> > Reenen Laurie schreef:
> >> Hi,
> >>
> >> I'm sure most of you have had this... is there an easy way to have a
> >> case statement that's based on "strings" rather than ordinal types. Is
> >> there somewhere a shortcut?
> >>
> >
> > You can use stringcase:
> > http://lazarus-ccr.sourceforge.net/docs/lcl/lclproc/stringcase.html
> >
> > Unfortunately without example. It is used in the Lazarus sources, so
> > maybe you find out how to use it from there.
> >
> > Vincent
>
> Can anyone say why there is no string case statement in Object Pascal? I've
> always wondered about this as sometimes it hard to avoid 10-20 If..then..else
> if.... statements.
>
> Would the compiled code of a string case statement even be any more efficient or
> is the benefit mostly in code readability?
In the case of strings, it would mostly be code readability. For ordinal
types, a case statement can be optimized using jump tables.
Michael.
More information about the Lazarus
mailing list