Skip to main content

truncate_string

Function truncate_string 

Source
pub fn truncate_string(s: &str, max_chars: usize) -> String
Expand description

Truncates a string to a maximum number of characters.

If the string exceeds max_chars, it’s truncated and the suffix (default “…”) is appended. The total length including suffix will not exceed max_chars.

§Example

use bel7_cli::truncate_string;

assert_eq!(truncate_string("Hello", 10), "Hello");
assert_eq!(truncate_string("Hello, World!", 8), "Hello...");