---
name: "bson_string_truncate"
section: "3"
platform: "linux"
package: "libbson-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/bson_string_truncate"
---

# bson\_string\_truncate(3)

**WARNING:**

Deprecated since version 1.29.0.

## SYNOPSIS

```
void
bson_string_truncate (bson_string_t *string, uint32_t len);
```

## PARAMETERS

- •

  **string**: A *bson\_string\_t*.

- •

  **len**: The new length of the string, excluding the trailing **\\0**.

## DESCRIPTION

Truncates the string so that it is **len** bytes in length. This must be smaller or equal to the current length of the string.

A **\\0** byte will be placed where the end of the string occurs.

**WARNING:**

This function is oblivious to UTF-8 structure. If truncation occurs in the middle of a UTF-8 byte sequence, the resulting *bson\_string\_t* will contain invalid UTF-8.

**WARNING:**

The length of the resulting string (including the **NULL** terminator) MUST NOT exceed **UINT32\_MAX**.

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
