limitBytes

fun String.limitBytes(maxBytes: Int): String(source)

Truncates a string to ensure its UTF-8 byte representation does not exceed maxBytes.

Return

The truncated string, or the original string if it's within the byte limit.

Receiver

The string to limit.

Parameters

maxBytes

The maximum allowed byte length.