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

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

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

Beitrag von mirkt »

Hello, Is there an elegant way of checking if string is in stringList? For now I am iterating and comparing..
Benutzeravatar
wolfbardo
uib-Team
Beiträge: 1354
Registriert: 01 Jul 2008, 12:10

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

Beitrag von wolfbardo »

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

code]
takeFirstStringContaining
[/code]

regards,
bardo wolf


OPSICONF 2024
https://opsi.org/en/opsiconf/

opsi-Basisworkshops:

22. - 25. 04. 2024


opsi support - uib gmbh
For productive opsi installations we recommend maintainance + support contracts which are the base of opsi development.

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?

Beitrag von mirkt »

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: 283
Registriert: 16 Dez 2014, 18:06

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

Beitrag von larsg »

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?

Beitrag von mirkt »

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!
Antworten