Sets in Xojo?

Does Xojo not have a data structure similar to sets in Python or Swift?
What I would like to do is have a set of strings (file extensions) that I could use in control expressions, for example:

var ext as string if ext not in someSetOfExtensionTypes then do some stuff end if

What I currently have is an awkward, long

if ext <> "txt" and ext <> "csv" and ext <> "cot"...

No doubt there’s a better way (even if there is not set functionality in Xojo)?

Thanks

InStr or InStrB ?

you could use Extends and Array(“txt”,“csv”)
or filetypegroup

@Phillip Bond — I agree with Markus. Xojo would use an Array instead

What is being suggested is that you store your set items in a string array and then you write an extension method to do an “In” lookup.

For example:

Var someSetOfExtensionTypes() As String = Array("txt", "csv", "cot") // add more as necessary

Var ext As String = "txt"
If Not someSetOfExtensionTypes.IsIn(ext) Then
  MessageBox("Not available.")
Else
  MessageBox("Available.")
End If

The IsIn() function in the above code is not built into Xojo, but IndexOf serves a similar purpose. So you can create your own IsIn (or whatever you want to call it) extension function for a String array that uses the IndexOf function. To do so, add this as a Global function in a module:

Function IsIn(Extends s() As String, value As String) As Boolean If s.IndexOf(value) >= 0 Then Return True Else Return False End If End Function

Use a Dictionary and .haskey ?

[code]var someSetOfExtensionTypes as new dictionary
someSetOfExtensionTypes.value (“txt”) = “text files”
someSetOfExtensionTypes.value (“csv”) = “comma separated files”
someSetOfExtensionTypes.value (“cot”) = “no idea”

var ext as string = “txt”
if not someSetOfExtensionTypes.haskey (ext) then
do some stuff
end if[/code]

what i had in mind with extends was
if ext.Have(“txt”, “csv”,“cot”) then
that the string class get a new method as described above.

InStr has been deprecated in favor of String.IndexOf, but point taken.
That’s a good idea, thanks.

(I’m still somewhat surprised that there isn’t a set type of data structure.)

If you like to get a plugin based Set class, you can check those here:

all in MBS Xojo Plugins.
Otherwise I would use a dictionary with nil as values.