Question: Consider the following snippet:

```
"12-18" -Contains "-"

```

You’d think this evaluates to `true`, but it doesn't. This will evaluate to `false` instead. I’m not sure why this happens, but it does.

To avoid this, you can use this instead:

```
"12-18".Contains("-")

```

Now the expression will evaluate to true.

Why does the first code snippet behave like that? Is there something special about `-` that doesn't play nicely with `-Contains`? [The documentation](http://technet.microsoft.com/en-us/library/hh847759.aspx) doesn't mention anything about it.

Answer: 
The `-Contains` operator doesn't do substring comparisons and the match must be on a complete string and is used to search collections.

From the documentation you linked to:

> 
> -Contains
>  Description: Containment operator. **Tells whether a collection of reference values includes a single test value.**
> 
> 
> 

In the example you provided you're working with a collection containing just one string item.

If you read the documentation you linked to you'll see an example that demonstrates this behaviour:

Examples:

```
PS C:\> "abc", "def" -Contains "def"
True

PS C:\> "Windows", "PowerShell" -Contains "Shell"
False  #Not an exact match

```

I think what you want is the [`-Match`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-6#-match) operator:

```
"12-18" -Match "-"

```

Which returns `True`.

**Important:** As pointed out in the comments and in the [linked documentation](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-6#-match), it should be noted that the `-Match` operator uses [regular expressions](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-6) to perform text matching.
* `like` is best, or at least easiest.
* `match` is used for regex comparisons.

Reference: *[About Comparison Operators](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators)*