Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a variable alongside a character 2

Status
Not open for further replies.

mvvilleza

MIS
Nov 23, 2000
114
PH
Hi all,

How can i display a variable alongside another character, something like:

$a = 1

If i type $a0 on the PS prompt it does not display any result.

PS D:\Test> $a=1
PS D:\Test> $a0
PS D:\Test>

My desired output is 10. I'm just new to powershell.
 
Another question is how do i tell switch not to display output to screen? Similar to Out-null
 
$($a)0" will work.

I'm not sure that I understand your second question.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
$a0 is seen as a separate variable name, which is why that doesn't work. There are a few other ways to do that as well:
Code:
[string]$a+"0"
"$a"+"0"
"$a"+0

Two ways to suppress output include assigning expressions to $null or piping them to Out-Null:
Code:
$null = Get-ChildItem
Get-ChildItem | Out-Null

I'm with EBGreen though, can you expand on your second question?
 
Hi to both of you,

Both of your solutions did work. Re: my second question, i'm trying to use the switch command and normally the result is displayed. I don't want the result displayed. As a sample code:

a=0
switch($a) {
0{"12"}
}

Then, if i type $a it should display 12. I've done this in VBScript using select case statement

a=0
Select Case a
Case "0"
a = "12"
End Select
WScript.Echo a


 
Hi all,


Found out the solution:

$a=1

switch($a)
{
1{$a="12"}
}
$a

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top