Adeel Ilyas
Adeel Ilyas

Reputation: 467

Powershell works differently for two similar operation

With reference to this post, I tried to do it with two different approaches and apparently PowerShell is responding differently but it should be same I think. Can anyone explain why it is different?

PS C:\> $x = "Hello
World"

PS C:\> $x
Hello
World

PS C:\> $x.Contains('`n')
False

PS C:\> $x.Contains("`n")
True

PS C:\> $x -Contains "`n"
False

PS C:\> $x -Contains '`n'
False

Upvotes: 1

Views: 75

Answers (1)

AdamL
AdamL

Reputation: 13141

Single quoted strings are not evaluated, so backtick is not being treated as escape character and the string is not being resolved as newline.

-contains is a containment comparison operator and only works on collections, just like -in.

So everything's fine :).

Upvotes: 1

Related Questions