Is there another way return the indices of every instance of a substring in an array besides old fashioned looping through indices?
$myarray = @('herp','dederp','dedoo','flerp')
$substring = 'erp'
$indices = @()
for ($i=0; $i -lt $myarray.length; $i++) {
if ($myarray[$i] -match $substring){
$indices = $indices + $i
}
}
$thisiswrong = @($myarray.IndexOf($substring))
The conditional inside that kind of for loop is kinda cumbersome, and $thisiswrong only ever gets a value of [-1]