How do compare a single variable to a whole array?
i want to compare a variable to an array and if it is not in there prefom a function if (variable A is not in Array B) { some function. } im creatin a program where i want to add variables to an array but only if they are not already in there
December 10th, 2010 6:53pm

Like this? PS C:\> $arr = "Red","Blue","Green" PS C:\> $a = "Red" PS C:\> $b = "Yellow" PS C:\> $arr -contains $a True PS C:\> $arr -contains $b False PS C:\> $a,$b | foreach {if ($arr -contains $_){write-host "Found $_"}} Found Red PS C:\>[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
December 10th, 2010 6:59pm

i have this im trying to find the sintax to see if uniqueword conatins word[i] its in a loop looking through a text file at the moment unique words has no variables in it if (!uniqueword[numWords].contains(word[i])) { counts = (counts + 1); uniqueword[i]= word[i]; } i should mention im using java and only learning programming so dont iunderstand alot of syntax
December 10th, 2010 7:03pm

Hash tables work, too: PS C:\> $ht = @{} PS C:\> "Red","Blue","Green","Red" |% {$ht[$_] = $null} PS C:\> $ht.keys Green Red Blue PS C:\> "blue","red","purple","yellow" |% {$ht[$_] = $null} PS C:\> $ht.keys Green yellow Red purple Blue PS C:\>[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
December 10th, 2010 7:06pm

im really sorry but i have no idea what that means at all is it pesudo code?
December 10th, 2010 7:10pm

That's Powershell code. You've posted in the Exchange Server Admin forum, and that's the scripting language used for management of Exchange servers. I think you probably need to ask in a different forum.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
December 10th, 2010 7:15pm

ic thank you im not sure since just made a file for first time
December 10th, 2010 7:18pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics