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)?
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