How do I tell powershell the end of a variable to be expanded into a string when it sits next to other alphabetic characters?
$StringToAdd = "iss"
$CompeteString = "Miss$StringToAddippi"
Thanks!
How do I tell powershell the end of a variable to be expanded into a string when it sits next to other alphabetic characters?
$StringToAdd = "iss"
$CompeteString = "Miss$StringToAddippi"
Thanks!
Use curly braces, {
and }
, to delimit the variable expansion. For example:
PS C:\> $StringToAdd = "iss"
PS C:\> $CompeteString = "Miss${StringToAdd}ippi"
PS C:\> $CompeteString
Mississippi
You can use $()
PS C:\> $StringToAdd = "iss"
PS C:\> $CompeteString = "Miss$($StringToAdd)ippi"
PS C:\> $CompeteString
Mississippi
The sub-expression operator for double-quoted strings is described here. Whatever is in the brackets should be evaluated first. This can be a variable or even an expression.
PS C:\> $CompeteString = "Miss$($StringToAdd.length * 2)ippi"
PS C:\> $CompeteString
Miss6ippi
$CompleteString="Miss"+$StringToAdd+"ippi"