# create a here-string with line breaks
PS:23 >$hs = @"
power
shell
rocks!
"@
PS:24 >$hs
power
shell
rocks
# test for line break , same as $hs -match "`n"
PS:25 >$hs -match "\n"
True
PS:26 >$hs -match "power\n"
True
# replace
PS:27 >$new = $hs -replace "power\n","power"
PS:28 >$new
powershell
rocks!
# same applies with `n
PS:29 >$new = $hs -replace "power`n","power"
PS:30 >$new
powershell
rocks!
# find string with line break
PS:39 >Select-String -InputObject $new -Pattern "powershell\n" -Quiet
True
# same with `n
PS:40 >Select-String -InputObject $new -Pattern "powershell`n" -Quiet
True
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog:
http://blogs.microsoft.co.il/blogs/scriptfanatic Quote:
> Hello,
>
> I am trying to search for a string pattern that includes new lines
> with the select-string cmdlet. I was looking for something like \n to
> match a new line in the regular expression but I can't seem to find
> anything.
>
> Also, what would be the general syntax to include a new line in a
> string (not speaking of regular expressions here) ?
>
> Any help is appreciated.
>
> Thanks,
> Xavier