Reputation: 3083
I have an array of data that looks like this:
Resource file d:\path\relevantDtata\WebConfigResource.resx is missing value for key /configuration/addSettings/add[@key="relevantData"]
Resource file d:\path\relevantDtata\WebConfigResource.resx is missing value for key /configuration/addSettings/add[@key="relevantData"]
Resource file d:\path\relevantDtata\WebConfigResource.resx is missing value for key /configuration/addSettings/add[@key="relevantData"]
Resource file d:\path\relevantDtata\WebConfigResource.resx is missing value for key /configuration/addSettings/add[@key="relevantData"]
Resource file d:\path\relevantDtata\WebConfigResource.resx is missing value for key /configuration/addSettings/add[@key="relevantData"]
Almost all of this data can be deleted except for a few short parts.
Resource file d:\path\
can go away
\WebConfigResource.resx is missing value for key /configuration/addSettings/add[@key="
can as well. and the file "]
can too.
Currently all this data is stored in $validationVar
I'm guessing I am wanting to playing around with substring but I'm not entirely sure what exactly needs to happen. Possibly something like the below?
$validationVar | % $_.substring(15)
Upvotes: 0
Views: 643
Reputation: 200523
I'd use -replace
with a regular expression:
$pattern = '^Resource file d:\\path\\(.*?)\\WebConfigResource\.resx is missing value for key /configuration/addSettings/add\[@key="(.*?)"\]'
$validationVar -replace $pattern, '$1$2'
Upvotes: 1
Reputation: 9854
$var1 = 'Resource file d:\path\relevantDtata\WebConfigResource.resx is missing value for key /configuration/addSettings/add[@key="relevantData"]'
PS C:\Scripts\so> $var1.Substring($var1.IndexOf(""""),$var1.IndexOf("""]")-$var1.IndexOf("="""))
"relevantData"
So you can do something like this
$validationVar | % { $_.Substring($_.IndexOf(""""),$_.IndexOf("""]")-$_.IndexOf("="""))}
or even better if you want the "RelevantData" then from this SO answer.
PS C:\> $validationVar | % {$_.Split('"')[1]}
relevantData
Upvotes: 2