stringstring-comparisonintersystems-cacheintersystemsobjectscript

Compare strings in Intersystems Cache Objectscript


Given:

2 strings strA, strB

I want:

To perform a comparison between them and return <0, =0 or >0, in Intersystems Cache ObjectScript.

So far:

I have found a function in the documentation that fulfills my needs StrComp. Unfortunately, this function is not part of Cache ObjectScript, but from Caché Basic.

I have wrapped the function as a classMethod of an utility class:

ClassMethod StrComp(
    pstrElem1 As %String,
    pstrElem2 As %String) As %Integer [ Language = basic ]
{
    Return StrComp(pstrElem1,pstrElem2)
}

Is this approach recommended? is there any function available?

Thanks in advance.


Solution

  • It's a bit unclear exactly what you want this string comparison to do, but it appears that you're looking for either the follows ] or sorts after ]] operator.

    Docs (taken from here):

    The syntax looks weird but it should do what you need.

    if "apple" ] "banana" ...
    if "apple" ]] "banana" ...