> For the complete documentation index, see [llms.txt](https://docs.shouldly.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shouldly.org/documentation/string/contain.md).

# Contain

## ShouldContain

```cs
var target = "Homer";
target.ShouldContain("Bart");
```

[<sup>snippet source</sup>](https://github.com/shouldly/shouldly/tree/master/src/DocumentationExamples/CodeExamples/StringExamples.ShouldContain.codeSample.approved.cs#L1-L2) <sup>|</sup> [<sup>anchor</sup>](#snippet-StringExamples.ShouldContain.codeSample.approved.cs)

**Exception**

```
target
    should contain
"Bart"
    but was actually
"Homer"
```

## ShouldContainWithoutWhitespace

```cs
var target = "Homer Simpson";
target.ShouldContainWithoutWhitespace(" Bart Simpson ");
```

[<sup>snippet source</sup>](https://github.com/shouldly/shouldly/tree/master/src/DocumentationExamples/CodeExamples/StringExamples.ShouldContainWithoutWhitespace.codeSample.approved.cs#L1-L2) <sup>|</sup> [<sup>anchor</sup>](#snippet-StringExamples.ShouldContainWithoutWhitespace.codeSample.approved.cs)

**Exception**

```
target
    should contain without whitespace
" Bart Simpson "
    but was actually
"Homer Simpson"
```

## ShouldNotContain

```cs
var target = "Homer";
target.ShouldNotContain("Home");
```

[<sup>snippet source</sup>](https://github.com/shouldly/shouldly/tree/master/src/DocumentationExamples/CodeExamples/StringExamples.ShouldNotContain.codeSample.approved.cs#L1-L2) <sup>|</sup> [<sup>anchor</sup>](#snippet-StringExamples.ShouldNotContain.codeSample.approved.cs)

**Exception**

```
target
    should not contain
"Home"
    but was actually
"Homer"
```

## ShouldContainAll

```cs
var target = "Homer Simpson";
target.ShouldContainAll(["Homer", "Bart"]);
```

[<sup>snippet source</sup>](https://github.com/shouldly/shouldly/tree/master/src/DocumentationExamples/CodeExamples/StringExamples.ShouldContainAll.codeSample.approved.cs#L1-L2) <sup>|</sup> [<sup>anchor</sup>](#snippet-StringExamples.ShouldContainAll.codeSample.approved.cs)

**Exception**

```
target
    should contain all
"Homer, Bart"
    but was actually
"Homer Simpson"
```

## ShouldContainAny

```cs
var target = "Homer";
target.ShouldContainAny(["Bart", "Marge"]);
```

[<sup>snippet source</sup>](https://github.com/shouldly/shouldly/tree/master/src/DocumentationExamples/CodeExamples/StringExamples.ShouldContainAny.codeSample.approved.cs#L1-L2) <sup>|</sup> [<sup>anchor</sup>](#snippet-StringExamples.ShouldContainAny.codeSample.approved.cs)

**Exception**

```
target
    should contain any
"Bart, Marge"
    but was actually
"Homer"
```

## ShouldNotContainAll

```cs
var target = "Homer Simpson";
target.ShouldNotContainAll(["Homer", "Simpson"]);
```

[<sup>snippet source</sup>](https://github.com/shouldly/shouldly/tree/master/src/DocumentationExamples/CodeExamples/StringExamples.ShouldNotContainAll.codeSample.approved.cs#L1-L2) <sup>|</sup> [<sup>anchor</sup>](#snippet-StringExamples.ShouldNotContainAll.codeSample.approved.cs)

**Exception**

```
target
    should not contain all
"Homer, Simpson"
    but was actually
"Homer Simpson"
```

## ShouldNotContainAny

```cs
var target = "Homer";
target.ShouldNotContainAny(["Home", "Moe"]);
```

[<sup>snippet source</sup>](https://github.com/shouldly/shouldly/tree/master/src/DocumentationExamples/CodeExamples/StringExamples.ShouldNotContainAny.codeSample.approved.cs#L1-L2) <sup>|</sup> [<sup>anchor</sup>](#snippet-StringExamples.ShouldNotContainAny.codeSample.approved.cs)

**Exception**

```
target
    should not contain any
"Home, Moe"
    but was actually
"Homer"
```
