Question

In C# I can do this:

public string[] MyStrings;
...
...
if(MyStrings.Contains("bob")) ...

In ObjectScript how is this done?

With %ArrayOfObjects type I don't see exactly what I am looking for here

What I have tried:

#Dim MyStrings As %ArrayOfDataTypes
do MyStrings.SetAt("User","User")   
do MyStrings.SetAt("Users","Users")
do MyStrings.SetAt("Group","Group")
do MyStrings.SetAt("Groups","Groups")

// if MyStrings contains Groups
if MyStrings.GetAt("Groups") '= ""
{
}
Was it helpful?

Solution

You've got it right. I would suggest making a subclass of %Library.ArrayOfDataTypes with your own methods on it, such as "contains".

It's probably a little safer to use your own classes that you do control than library classes that you don't anyway (though in a pinch you could always use %Dictionary package methods to switch all references to a library class to a new class of your design, so it's not really that big a deal).

OTHER TIPS

It sounds like you want the .IsDefined() method. For example:

#Dim MyStrings As %ArrayOfDataTypes
do MyStrings.SetAt("User","User")   
do MyStrings.SetAt("Users","Users")
do MyStrings.SetAt("Group","Group")
do MyStrings.SetAt("Groups","Groups")

// if MyStrings contains Groups
if MyStrings.IsDefined("Groups")
{
    // code to execute if MyStrings contained "Groups"
}

I am not familiar with that language, but could you try something like:

//declare myString to hold a string
set myString = MyStrings.GetNext("")
While myString '= ""
{
    if MyStrings.GetAt(myString) '= ""  //Or should it be something like myString.value?  Is there a way to check the type of an object to see if it is a string?
    {
        //Do something here.  Exit loop if you are trying to find just a match.
    }
}

I am assuming '= is equivalent to != in C#.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top