Answer the question
In order to leave comments, you need to log in
How to replace a substring with a value from a Dictionary?
The bottom line is this: you need to replace all occurrences of the @some_text type with a value from the dictionary
. There is such a script:
[string]$str = "-Password '@Password' -Branches '@BranchList'"
[System.Collections.Specialized.OrderedDictionary]$ValuesForParameters = @{}
$ValuesForParameters.Add("BranchList", "Replaced BranchList")
$ValuesForParameters.Add("Password", "Replaced Password")
$regularExpression = "(?<='@)(.*?)(?=')"
[string]$result = $str -replace $regularExpression, $ValuesForParameters['$1']
$ValuesForParameters.Keys
Write-Host $result
-Password '@' -Branches '@'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question