Ouput format for strings

It should be pretty easy, but I’m stuck on this.

I’m trying to get all installed version for machines. And I need to get unique values from registry keys.

I’ve this relevance code:

q: unique values of (value "DisplayVersion" of it as string as trimmed string) of keys whose ( value "DisplayName" of it as string as trimmed string as lowercase contains "firefox") of keys "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registry ; native registry) A: 46 A: 46.0.1 T: 5.681 ms

I need to get just one answer, because it’s actually the same.

How could I get that?

Those don’t look like the same version to me? 46 != 46.0.1 …

Are you just looking for the “Major Versions”? You might be able to do something like

q: unique values of (if it contains "." then preceding text of first "." of it else it) of (value "DisplayVersion" of it as string as trimmed string) of keys whose ( value "DisplayName" of it as string as trimmed string as lowercase contains "firefox") of keys "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registry ; native registry)
A: 47

Yes, doing that, I used something similar :slight_smile:
Just another concern, If I get few values, I want to exclude the last one, e.g.
I get this:

46 47 48

Expected output:

46 47

How could I exclude the last value from the output, is it possible?

The number of answers will be different in every machine.

Well, I was about to reply back that this is not a valid use case, but it got me curious and I think it may have let me to a bug in the tuple string item evaluator.

Items in a list are not ordered by definition and you should not rely on any kind of ordering like “remove the last one”. But I’ve had cases where I need to get only the first out of possibly multiple results (like finding a MAC address on a host).

While sets are not ordered in principle, in practice I find they generally are; and operations like “unique values of” that create a Set, generally create an Ordered Set. We can concatenate the results together with the comma-space characters ", ", and then evaluate them as Tuple String Items. Then we can use the “integers in ()” inspector to just get a particular few of those tuple string items. This first let me to this:

q: number of tuple string items of ("one, two, three")
A: 3
T: 0.081 ms
I: singular integer

q: tuple string items (1;2) of ("one, two, three")
A: two
A: three
T: 0.042 ms
I: plural string

q: tuple string items (integers in (0, number of tuple string items of it - 2)) of ("one, two, three")
A: one
A: two
T: 0.095 ms
I: plural string

What about edge cases? Need to test if there are fewer than three results, or only one result, so …

        q: tuple string items (integers in (0, number of tuple string items of it - 2)) of ("one")
        A: one
        A: one
        T: 0.100 ms
        I: plural string

Whoa, that’s not what I was expecting (I was actually expecting an error). Based on this, when I retrieve tuple string item -1, I get the first item again. At first I thought that negative indexes might walk back from the last item, but no, it seems that passing any negative index returns the first item:

q: tuple string items (-2) of ("one, two, three")
A: one
T: 0.046 ms
I: plural string

So, it takes a little case logic…but again, I’m reaching here, what is it that you really want? If there’s one result, print it? If there’s more than one, present one less than the total number of results? If there were five results, you want to show the first four of them?

q: tuple string items (integers in (0, (if number of tuple string items of it > 2 then number of tuple string items of it - 2 else 0))) of ("one")
A: one
T: 0.089 ms
I: plural string

q: tuple string items (integers in (0, (if number of tuple string items of it > 2 then number of tuple string items of it - 2 else 0))) of ("one, two")
A: one
T: 0.095 ms
I: plural string

q: tuple string items (integers in (0, (if number of tuple string items of it > 2 then number of tuple string items of it - 2 else 0))) of ("one, two, three")
A: one
A: two
T: 0.135 ms
I: plural string

Oh, and by the way I actually only get one result for my machine…but I think this might work:

q: tuple string items (integers in (0, (if number of tuple string items of it > 2 then number of tuple string items of it - 2 else 0))) of concatenation ", " of unique values of (if it contains "." then preceding text of first "." of it else it) of (value "DisplayVersion" of it as string as trimmed string) of keys whose ( value "DisplayName" of it as string as trimmed string as lowercase contains "firefox") of keys "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registry ; native registry)