---
title: The “Contains()” Function
description: "Thought for 20 seconds # Understanding the Contains() Function in Assette Expressions ## Introduction In Assette, expressions are powerful tools used within Data Objects to manipulate, compare, and evaluate data for client reports and presentations. The `Contains()` function is an…"
url: "https://learn.assette.com/docs/the-contains-function/"
updated: "2025-02-27"
category: Developers / Developer Tools / Data Object Editor / Expressions
---

# The “Contains()” Function

Thought for 20 seconds

# Understanding the Contains() Function in Assette Expressions

## Introduction

In Assette, expressions are powerful tools used within Data Objects to manipulate, compare, and evaluate data for client reports and presentations. The `Contains()` function is an essential component in these expressions, enabling developers to determine whether a specific substring exists within a string, with the option to ignore case sensitivity.

This article provides a comprehensive overview of the `Contains()` function in Assette, including its purpose, syntax, usage in expressions, practical examples, and best practices for incorporating it effectively into your data processing workflows.

## Purpose of `Contains()`

The `Contains()` function is used to check whether:

- A **string** (`mainString`) contains a specific **substring** (`subString`).

It returns a boolean value:

- **`True`**: If the substring is found within the main string.
- **`False`**: If the substring is not found.

An optional `ignoreCase` parameter allows you to specify whether the search should be case-sensitive.

This function is crucial for:

- **Conditional Logic**: Making decisions based on the presence of certain values.
- **Data Validation**: Ensuring data meets specific criteria.
- **Filtering Data**: Selecting records that match certain conditions.

## Syntax

- **`mainString`**: The string to search within.
- **`subString`**: The substring to search for.
- **`ignoreCase`**: (Optional) A boolean value indicating whether to ignore case sensitivity. If set to `true`, the search is case-insensitive. If omitted or set to `false`, the search is case-sensitive.

```
Contains(mainString, subString, ignoreCase: true)
```

## Usage in Expressions

### Case-Sensitive Search

If `ignoreCase` is omitted or set to `false`, the `Contains()` function performs a case-sensitive search.

- Returns `True` only if `documentTitle` contains "Quarterly Report" with the exact casing.
- Returns `False` if the casing differs.

```
Contains(documentTitle, "Quarterly Report")
```

### Case-Insensitive Search

By setting `ignoreCase` to `true`, the `Contains()` function will perform a case-insensitive search.

- Returns `True` if `documentTitle` contains "Quarterly Report", "quarterly report", "QUARTERLY REPORT", etc.
- Ignores case differences between `mainString` and `subString`.

```
Contains(documentTitle, "quarterly report", ignoreCase: true)
```

## Practical Examples

### Filtering Transactions

**Objective:** Identify if a transaction is of a specific type, considering case sensitivity.

**Explanation:**

- Performs a case-sensitive search for "Refund" in `transactionType`.
- Use this when the exact casing is important.

```
Contains(transactionType, "Refund")
```

## Best Practices

1. **Specify `ignoreCase` When Necessary**
   - Be explicit about case sensitivity by setting `ignoreCase` to `true` or `false`.
2. **Understand Default Behavior**
   - If `ignoreCase` is optional and omitted, know that the default is case-sensitive. Always specify `ignoreCase` if case insensitivity is required.
3. **Trim Whitespace**
   - Remove unnecessary spaces using `Trim()`.
4. **Avoid False Positives**
   - Be precise with `subString` to prevent unintended matches.

## Common Mistakes to Avoid

- **Ignoring Case Sensitivity**
  - Not specifying `ignoreCase` can lead to missed matches or false positives.
- **Assuming Default Case Sensitivity**
  - If unsure about the default behavior, always specify the `ignoreCase` parameter.
- **Not Handling Null Values**
  - Attempting to use `Contains()` on a `null` `mainString` may cause errors.
- **Assuming Exact Matches**
  - Remember that `Contains()` searches for any occurrence of `subString` within `mainString`.
