opsi-winst / opsi-script: Checking if string is in the stringList?

mirkt
Beiträge: 95
Registriert: 05 Jun 2013, 09:39
Wohnort: Lithuania

opsi-winst / opsi-script: Checking if string is in the stringList?

Beitragvon mirkt » 28 Nov 2017, 15:41

Hello, Is there an elegant way of checking if string is in stringList? For now I am iterating and comparing..

Benutzeravatar
wolfbardo
Beiträge: 1080
Registriert: 01 Jul 2008, 12:10

Re: opsi-winst / opsi-script: Checking if string is in the stringList?

Beitragvon wolfbardo » 30 Nov 2017, 12:16

https://download.uib.de/opsi_stable/doc ... anual.html

code]
takeFirstStringContaining
[/code]

regards,
bardo wolf


opsi workshops in Mainz

Basis 27.-30.8.2018

Paketierung: Vertiefung 06.-07.9.2018

Basis 24.-27.9.2018

Basis 5.-8.11.2018

Paketierung: Einführung13.-14.11.2018

Basis 3.-6.12.2018


opsi support by uib gmbh

http://www.uib.de

mirkt
Beiträge: 95
Registriert: 05 Jun 2013, 09:39
Wohnort: Lithuania

Re: opsi-winst / opsi-script: Checking if string is in the stringList?

Beitragvon mirkt » 30 Nov 2017, 15:30

Dear Wolf, that is not really what I was asking.. In many situations I have some kind of value and need to check if it is or it is not in some kind of a list (blacklist, whitelist, etc..).. "Contains" is not what I need.. I need "equals"! :) Funny things could happen with "contains" (ex. paths)..

Code: Alles auswählen

[Actions]
requiredWinstVersion >= "4.12.0.7"
encoding=utf8
LogLevel = "1"

DefVar $Something$
DefStringList $SomethingAllowed$

Set $Something$ = "a"
Set $SomethingAllowed$ = createStringList('ab', 'bc', 'cd')

if not(takeFirstStringContaining($SomethingAllowed$, $Something$) = "")
   Comment "I was there.."
endif


would result true:

Code: Alles auswählen

[6] [Lap 30 16:22:11:132] If
[7] [Lap 30 16:22:11:134]   takeFirstStringContaining($SomethingAllowed$, $Something$) = ""   <<< result false
[6] [Lap 30 16:22:11:137]   not(takeFirstStringContaining($SomethingAllowed$, $Something$) = "")   <<< result true
[6] [Lap 30 16:22:11:138] Then
[5] [Lap 30 16:22:11:140]   comment: I was there..
[6] [Lap 30 16:22:11:146] EndIf


Funny way of doing it could be:

Code: Alles auswählen

if not(count($SomethingAllowed$) = count(removeFromListByMatch($Something$, $SomethingAllowed$)))
   Comment "I was there.."
endif


There should be a better way of checking it element is in a list..

larsg
Beiträge: 195
Registriert: 16 Dez 2014, 18:06

Re: opsi-winst / opsi-script: Checking if string is in the stringList?

Beitragvon larsg » 14 Mär 2018, 15:05

Code: Alles auswählen

if not(Count(GetListContaining($SomethingAllowed$,$Something$)) = "0")
   Comment "I was there.."
endif

;or

if (Count(GetListContaining($SomethingAllowed$,$Something$)) INT> "0")
   Comment "I was there.."
endif




opsi works, and it works very well if used correctly. thats all i want and need.

mirkt
Beiträge: 95
Registriert: 05 Jun 2013, 09:39
Wohnort: Lithuania

Re: opsi-winst / opsi-script: Checking if string is in the stringList?

Beitragvon mirkt » 23 Apr 2018, 15:19

larsg: The problem is with ..Containing – string - substring:)

The solution: getSubListByMatch (<search string>, <target list>) :stringlist //since 4.12.0.14

Thank you, OPSI developers!