Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

working with strings

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 09-27-2007   #1 (permalink)
ASCHNEIDER146
Guest


 

working with strings

Could someone please explain why this happens like this

PS 1 > $a = "_string"
PS 2 > $a
_string
PS 3 > $b = "string $a_string"
PS 4 > $b
string

I would expect $b to be "string _string_string" as it does if I do
this

PS 8 > $b = "string" + $a + "_string"
PS 9 > $b
string_string_string

Thanks in advance

Andy


My System SpecsSystem Spec
Old 09-27-2007   #2 (permalink)
Brandon Shell
Guest


 

Re: working with strings

This is because _ could be part of the name of the variable

try this instead
PS> $a = "_string"
PS> $b = "string$($a)_string"
PS> $b
string_string_string


"ASCHNEIDER146" <aschneider146@xxxxxx> wrote in message
news:1190903446.175530.43700@xxxxxx
Quote:

> Could someone please explain why this happens like this
>
> PS 1 > $a = "_string"
> PS 2 > $a
> _string
> PS 3 > $b = "string $a_string"
> PS 4 > $b
> string
>
> I would expect $b to be "string _string_string" as it does if I do
> this
>
> PS 8 > $b = "string" + $a + "_string"
> PS 9 > $b
> string_string_string
>
> Thanks in advance
>
> Andy
>
My System SpecsSystem Spec
Old 09-27-2007   #3 (permalink)
Kiron
Guest


 

Re: working with strings

You could also avoid this by delimiting the variable with braces:

$a = "_string"
$b = "string ${a}_string"

--
Kiron

My System SpecsSystem Spec
Old 09-27-2007   #4 (permalink)
ASCHNEIDER146
Guest


 

Re: working with strings

On Sep 27, 7:30 am, ASCHNEIDER146 <aschneider...@xxxxxx> wrote:
Quote:

> Could someone please explain why this happens like this
>
> PS 1 > $a = "_string"
> PS 2 > $a
> _string
> PS 3 > $b = "string $a_string"
> PS 4 > $b
> string
>
> I would expect $b to be "string _string_string" as it does if I do
> this
>
> PS 8 > $b = "string" + $a + "_string"
> PS 9 > $b
> string_string_string
>
> Thanks in advance
>
> Andy
That makes sense. Thanks for the clarification.

Andy

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using $ signs in strings greatbarrier86 PowerShell 11 05-21-2008 12:06 PM
-f paramater in strings thomas lee PowerShell 4 04-02-2008 04:33 PM
comparing secure strings... Ben Christian PowerShell 3 04-02-2008 03:42 PM
Comparing strings - is it a bug? Tibor Soos PowerShell 7 03-13-2008 08:04 PM
Resource strings Jarlaxle PowerShell 3 03-04-2008 02:04 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008