![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Mix single and double quotes I don't know if this is a bug or not (yet?) (full) supported. "Mix" here obviously means "Alternate". It doesn't work at all in expression mode : '$X'"Y"'$X' or "Y"'$X'"Y" raise an error. It "half-works" in command mode : # <sq>$X</sq><dq>Y</dq><sq>$X</sq> write-host '$X'"Y"'$X' returns : $X Y $X or # <dq>Y</dq><sq>$X</sq><dq>Y</dq> write-host "Y"'$X'"Y" returns : Y $X Y As you see it "half-works" as spaces are added and we should expect : $XY$X and Y$XY as returns. Regards, -- Jean - JMST Belgium |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Mix single and double quotes try this syntax @' " can't we see '' ' " " that we are mixxing something '@ betwene the @' and the '@ its totally literal, no matter how many double or single quotes there are, or even ` escape codes.. they don't get escaped. one thing to no is its a tedious syntax you have to have them on different lines, and even an extra space after the @' will make it bomb. Jean wrote: > I don't know if this is a bug or not (yet?) (full) supported. > > "Mix" here obviously means "Alternate". > > It doesn't work at all in expression mode : > > '$X'"Y"'$X' > or > "Y"'$X'"Y" > > raise an error. > > It "half-works" in command mode : > # <sq>$X</sq><dq>Y</dq><sq>$X</sq> > write-host '$X'"Y"'$X' > > returns : > > $X Y $X > > or > > # <dq>Y</dq><sq>$X</sq><dq>Y</dq> > write-host "Y"'$X'"Y" > > returns : > > Y $X Y > > As you see it "half-works" as spaces are added and we should expect : > $XY$X and Y$XY as returns. > > Regards, > > -- > Jean - JMST > Belgium |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Mix single and double quotes Some more workarounds: a) write-host "Y"'$X'"Y" -s "" b) write-host ("Y"+'$X'+"Y") c) $ofs="";[string]("Y",'$X',"Y") d) ("Y"+'$X'+"Y") -- greetings dreeschkind "Jean" wrote: > I don't know if this is a bug or not (yet?) (full) supported. > > "Mix" here obviously means "Alternate". > > It doesn't work at all in expression mode : > > '$X'"Y"'$X' > or > "Y"'$X'"Y" > > raise an error. > > It "half-works" in command mode : > # <sq>$X</sq><dq>Y</dq><sq>$X</sq> > write-host '$X'"Y"'$X' > > returns : > > $X Y $X > > or > > # <dq>Y</dq><sq>$X</sq><dq>Y</dq> > write-host "Y"'$X'"Y" > > returns : > > Y $X Y > > As you see it "half-works" as spaces are added and we should expect : > $XY$X and Y$XY as returns. > > Regards, > > -- > Jean - JMST > Belgium > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Mix single and double quotes > try this syntax > > @' > " can't we see '' ' " " that we are mixxing something > '@ > Thank you for your answer and the trick. But I wanted a "mix" preserving "expand" double quote contents and "unexpand" single quote contents. ie to be able to do : $test="Z" write-host '$test'"$test"'$test' giving $testZ$test Regards, -- Jean - JMST Belgium |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Mix single and double quotes > Some more workarounds: > > a) write-host "Y"'$X'"Y" -s "" > > b) write-host ("Y"+'$X'+"Y") > > c) $ofs="";[string]("Y",'$X',"Y") > > d) ("Y"+'$X'+"Y") > Thank you. b) and d) are my favorites :-) As in my project I "need" <sq></sq><dq></dq> I use `b to start the double quote string to get rid the extra space, ie : write-host '$SINGLE'"`bDOUBLE" BTW, is it a way to know if a string variable is single or double quoted ? Regards, -- Jean - JMST Belgium |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Mix single and double quotes "Jean" wrote: > BTW, is it a way to know if a string variable is single or double > quoted ? AFAIK this is not directly possible. Everything in double quotes will be expanded as soon as it is being assigned to a string variable. However, using non printable characters, you can get a hint on how the string has been created: >$a = "`a123" >$a.length 4 >$a = '`a123' >$a.length 5 -- greetings dreeschkind |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Mix single and double quotes "Jean" <repondre@groupe.svp> wrote in message news:mn.b03f7d6a30ab6da4.56820@windows... > But I wanted a "mix" preserving "expand" double quote contents and > "unexpand" single quote contents. > > ie to be able to do : > > $test="Z" > write-host '$test'"$test"'$test' > giving > $testZ$test In an expandable string you can prevent expansion by escaping the $ sign: PS> write-host "`$test$test`$test" $testZ$test PS> "`$test$test`$test" $testZ$test A bit more fun: PS> $a='`$test$test`$test' PS> $a `$test$test`$test PS> $b='"'+$a+'"' PS> $b "`$test$test`$test" PS> invoke-expression $b $testZ$test Or a very silly way to get the same result: PS> "$" $ PS> "$$test$test$$test" $testZ$test Jacques |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Mix single and double quotes > In an expandable string you can prevent expansion by escaping the $ sign: Thank you, this complete well the topic. Don't know yet which way I'll choice from answers. To come back to my questioning I conclude alternate single and double quotes in command mode as in : write-host "Y"'$X'"Y" isn't really supported/intended and so could be breaked in future PS's releases. Regards, -- Jean - JMST Belgium |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Mix single and double quotes > AFAIK this is not directly possible. In fact, to be possible, imho this would imply a [unexpandedstring] type or an "unexpanded" property in [string] type. Regards, -- Jean - JMST Belgium |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Mix single and double quotes "Jean" <repondre@groupe.svp> wrote in message news:mn.b5967d6a27089c2e.56820@windows... > To come back to my questioning I conclude alternate single and double > quotes in command mode as in : write-host "Y"'$X'"Y" isn't really > supported/intended and so could be breaked in future PS's releases. I hadn't thought about that. :| I already tend to just use simple escaping when needed, inserting a ` for any special character in a string. One thing that is particularly handy about this approach is that you can even escape linear whitespace with `. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: Remove double quotes from a string | .NET General | |||
| shortcuts targetpath has double quotes and won't work? | PowerShell | |||
| Need info on how to escape double quotes | PowerShell | |||
| Need info on how to escape double quotes | PowerShell | |||
| here-string with single and double quotes | PowerShell | |||