I’m trying to create a query code, in which I want to capture all values (from a set) that contain “Sheriff” – i.e., a prefix before many names that fall under my $OfficialsPlayers values – and also exclude one name (e.g., Sheriff John Brown").
I thought that the following would work, just for querying the first part of what I’m seeking:
What data-type is $OfficialsPlayers? The final ‘s’ suggests it is a List or sEt in which case a different strategy might be needed. Can you confirm the data types of the target attributes?
Thanks. I actually first referred to your page, and used it to construct the code I posted above. Honestly thought it would work; was a bit surprised when it didn’t.
Thank you! It took a little while for the code to kick in, but then the agent produced the desired results. It’s terrific.
BTW, on your List/Set.icontains(“regex”) page, under the Testing “does not contain” and the “Use of parentheses after the ! …” section, the example shows the exclamation point just to the left of the first open parentheses. FWIW…
Yes, because that was from the source on which the example was based. I’m not sure what’s changed since but it does now appear that (!$AttrName) works better than !($AttrName).
But, stepping away from the magic aspect of code (i.e. not understood but just works) the issue here is that parentheses help Tinderbox understand your constraint. In theory:
!$OfficialsPlayers.contains("Sheriff John Brown")
intuitively ought to work. But ‘NOT’ query for regex can be problematic. Occasionally, Tinderbox may stumble at this step, so extra guiding parentheses are needed. In the past the syntax seemed to be !() but now appears to be (!). If you don’t want to guess if parentheses are needed with a negative test you can choose to always add parentheses as Tinderbox won’t mind.
I’ve updated the articles for String & list versions of .contains() and .icontains().
Yes, these are date formats, but i the context above we’re not using these for data. We’re using “,” to somehow format a String or set. it is not clear to me what the different flags are and when I can or should use them.
[Set].format(separator). converts a set to a string, inserting the string separator between elements. For example, $MySet.format(",") returns a comma-separated list.
I was confused by your use of ‘flags’. It is perhaps more useful to read first about format(). Even if you are more likely to use the dot-operator version, the original operator helps show how different source data types affect the result.
Here, you are referring without clarification_ to the formatting of lists which would have been a better question. I don’t mean that as rebuke … but garbage-in-garbage out. There are no format()-specific designators. What happens/what’s needed as input is entirely dependent on the source data type.
With a list, thus in Tinderbox a List-type or Set-type, the operator takes a single argument the ‘formatString’: this is an unevaluated string.formatString is the string used in the function’s output to replace the semicolon in the stored version of a list. Thus ", " places a comma+space between each term, whilst “\n” inserts a line break between each term etc. So " banana " would place space+banana+space between teach item, etc.
I’m confused as to how this is not clear in the existing documentation, though it seems there is potentially an issue over the user’s vs. author’s starting PoV. I’m open to suggestions as to how to make this better.
For specific data types, such as ‘Date’ type, there are a number of special format strings that can be used to give precise versions of formatString when rendering the source item(s).
Formerly, I would have used a .replace(';",", ") to get rid of the “;”, `.format(", ")’ seems more efficient. Note, I introduce a space after the “,” and I get a comma separated lists from the sets: