If you’re in SharePoint 2010 Management Shell, the time might come that you need to concatenate a string with a variable, and echo it on the screen, to show what’s happening as it’s happening. However, it’s not as straight forward as it is in C# or VB.Net.
First, we define a string (or whatever) for a variable:
$myVar="This Is My string variable.
But – you don’t want to show just that on the screen, so you want to concatenate it with something more explanatory, like: ‘Variable: ‘ followed by the actual variable.
First off, we’d use ‘echo’ (an alias for write-output) in order to display it all on the screen and enclose the rest in parentheses, separated by a ‘+’ sign:
$myVar="This Is My string variable.
echo $("Variable: " + $myVar)
That’s all there is to it!
All Things DotNet Discussed – Winforms/ASP.Net/SharePoint/WPF
Leave a reply
You must be logged in to post a comment.