Bug or limitation ?
Typing:
$a='1`n2`n3'
$a.Split(`n)
result is:
1
2
3
result expected :
1
2
3
Typing:
$a='1$var2$var3'
$a.Split('$var')
result is:
1
2
3
result expected :
1
2
3
Regards,
--
Jean - JMST
Belgium
Bug or limitation ?
Typing:
$a='1`n2`n3'
$a.Split(`n)
result is:
1
2
3
result expected :
1
2
3
Typing:
$a='1$var2$var3'
$a.Split('$var')
result is:
1
2
3
result expected :
1
2
3
Regards,
--
Jean - JMST
Belgium
> $a.Split(`n)
read :
$a.Split('`n')
--
Jean - JMST
Belgium
Another interesting observation is the difference in behaviour when
using Split() using paired double quotes or paired apostrophes.
PS Env:\> $a = 'a`nb`nc'
PS Env:\> $a.Split("`n")
a`nb`nc
PS Env:\> $a.Split('`n')
a
b
c
PS Env:\>
Andrew Watt MVP
On Wed, 27 Sep 2006 22:16:12 +0200, Jean <repondre@groupe.svp> wrote:
>Bug or limitation ?
>
>Typing:
>
>$a='1`n2`n3'
>$a.Split(`n)
>
>result is:
>
>1
>
>2
>
>3
>
>result expected :
>
>1
>2
>3
>
>Typing:
>
>$a='1$var2$var3'
>$a.Split('$var')
>
>result is:
>
>1
>
>
>
>2
>
>
>
>3
>
>result expected :
>
>1
>2
>3
>
>Regards,
This is by design.
`n is no longer processed in single-quoted strings.
PS C:\> $a="1`n2`n3"
PS C:\> $a.split("`n")
1
2
3
--
Wei Wu [MSFT]
Windows PowerShell Team
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jean" wrote:
> > $a.Split(`n)
>
> read :
>
> $a.Split('`n')
>
> --
> Jean - JMST
> Belgium
>
>
>
> This is by design.
> `n is no longer processed in single-quoted strings.
That's right, James Truher told me that recently.
But if I write (with single quotes) :
$a='1`n2`n3'
output is
1`n2`n3
and so if I write (with single quotes)
$a.Split('`n')
I expect Split searches `n and not <cr> as '`n' is `n
And it's as it works but some extra spaces are added in output ... why
?
Regards,
--
Jean - JMST
Belgium
> Another interesting observation is the difference in behaviour when
> using Split() using paired double quotes or paired apostrophes.
See Wei Wu answer :
"This is by design.
`n is no longer processed in single-quoted strings."
and from RELEASENOTES.RTF :
"-- Windows PowerShell does not interpret a backtick (`) as an escape
character when it appears within single quotation marks. This applies
to all single-quoted strings, including strings in scripts."
Regards,
--
Jean - JMST
Belgium
> some extra spaces
read : some extra lines
--
Jean - JMST
Belgium
Thanks, Wei Wu. But have a look at the following:
PS C:\Documents and Settings\Andrew Watt> $DoubleQuotes = "a`nb`nc"
PS C:\Documents and Settings\Andrew Watt> $DoubleQuotes.Split("`n")
a
b
c
PS C:\Documents and Settings\Andrew Watt> $DoubleQuotes.Split('`n')
a
b
c
PS C:\Documents and Settings\Andrew Watt> $SingleQuotes = 'a`nb`nc'
PS C:\Documents and Settings\Andrew Watt> $SingleQuotes.Split("`n")
a`nb`nc
PS C:\Documents and Settings\Andrew Watt> $SingleQuotes.Split('`n')
a
b
c
PS C:\Documents and Settings\Andrew Watt>
If $DoubleQuotes.Split('`n') doesn't process a single-quoted string
then the supposed separator should, I think, be literal back tick
followed by literal n. Since that literal (unprocessed) sequence
doesn't occur in $SingleQuotes then the whole string should be output
unchanged, I think. But $DoubleQuotes.Split('`n') seems to process
the `n.
For $SingleQuotes.Split('`n') why is there a blank line between the a
the b and the c? If I have
$b = 'a,b,c'
and use
$b.Split(',')
the separator isn't displayed.
PS C:\Documents and Settings\Andrew Watt> $b = 'a,b,c'
PS C:\Documents and Settings\Andrew Watt> $b.Split(',')
a
b
c
PS C:\Documents and Settings\Andrew Watt>
Why should it be for $SingleQuotes.Split('`n')?
Thanks
Andrew Watt MVP
On Wed, 27 Sep 2006 13:46:01 -0700, Wei Wu [MSFT]
<wei.wu@discussions.microsoft.com> wrote:
>This is by design.
>`n is no longer processed in single-quoted strings.
>
>PS C:\> $a="1`n2`n3"
>PS C:\> $a.split("`n")
>1
>2
>3
I'd call this a bug.
--
greetings
dreeschkind
"Jean" wrote:
> Bug or limitation ?
>
> Typing:
>
> $a='1`n2`n3'
> $a.Split(`n)
>
> result is:
>
> 1
>
> 2
>
> 3
>
> result expected :
>
> 1
> 2
> 3
>
> Typing:
>
> $a='1$var2$var3'
> $a.Split('$var')
>
> result is:
>
> 1
>
>
>
> 2
>
>
>
> 3
>
> result expected :
>
> 1
> 2
> 3
>
> Regards,
>
> --
> Jean - JMST
> Belgium
>
>
>
Me too
(more an addition to the old one, making it worse)
gr /\/\o\/\/
"dreeschkind" wrote:
> I'd call this a bug.
>
> --
> greetings
> dreeschkind
>
> "Jean" wrote:
>
> > Bug or limitation ?
> >
> > Typing:
> >
> > $a='1`n2`n3'
> > $a.Split(`n)
> >
> > result is:
> >
> > 1
> >
> > 2
> >
> > 3
> >
> > result expected :
> >
> > 1
> > 2
> > 3
> >
> > Typing:
> >
> > $a='1$var2$var3'
> > $a.Split('$var')
> >
> > result is:
> >
> > 1
> >
> >
> >
> > 2
> >
> >
> >
> > 3
> >
> > result expected :
> >
> > 1
> > 2
> > 3
> >
> > Regards,
> >
> > --
> > Jean - JMST
> > Belgium
> >
> >
> >
| Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Quote of the day | zigzag3143 | Chillout Room | 142 | 13 Jan 2012 |
| Quote Fixing | Joseph Meehan | Live Mail | 6 | 07 Feb 2008 |
| My quote of the day | kirk jim | Vista General | 8 | 22 Mar 2007 |